/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.Instance;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.lineage.server.GeneralThreadPool;
import com.lineage.server.IdFactory;
import com.lineage.server.codes.ActionCodes;
import com.lineage.server.datatables.DoorTable;
import com.lineage.server.datatables.MobGroupTable;
import com.lineage.server.datatables.NpcTable;
import com.lineage.server.datatables.TrapTable;
import com.lineage.server.model.L1HardinQuest;
import com.lineage.server.model.L1Inventory;
import com.lineage.server.model.L1Location;
import com.lineage.server.model.L1MobGroupSpawn;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.model.L1World;
import com.lineage.server.model.skill.L1SkillId;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.model.trap.L1Trap;
import com.lineage.server.model.trap.L1WorldTraps;
import com.lineage.server.packetserver.S_BlueMessage;
import com.lineage.server.packetserver.S_NPCPack;
import com.lineage.server.packetserver.S_NPCTalkReturn;
import com.lineage.server.packetserver.S_NpcChatPacket;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.packetserver.S_SkillSound;
import com.lineage.server.random.RandomGenerator;
import com.lineage.server.random.RandomGeneratorFactory;
import com.lineage.server.templates.L1DoorGfx;
import com.lineage.server.types.Point;
import com.lineage.server.utils.collections.Lists;

/**
 * Class <code>L1HardinQuestInstance</code> 哈丁副本控制项.
 * 
 * @author jrwz
 * @version 2012-7-13下午03:41:50
 * @see com.lineage.server.model.Instance
 * @since JDK1.7
 */
public final class L1HardinQuestInstance {

    /**
     * 召唤袭击者.
     */
    class AssailantSpawn extends TimerTask {

        /**
         * 开始.
         */
        public void begin() {
            final Timer timer = new Timer();
            timer.scheduleAtFixedRate(this, 10 * 1000, 160 * 1000);
        }

        /*
         * 7596 呀！是讴歌！
         */
        @Override
        public void run() {
            if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) {
                if (L1HardinQuestInstance.this.getBoneLaidStatus() == 0) {
                    final RandomGenerator rd = RandomGeneratorFactory
                            .getSharedRandom();
                    final int i = rd.nextInt(3);
                    final int mobGroupLeaderId = MobGroupTable.getInstance()
                            .getTemplate(85 + i).getLeaderId();
                    L1HardinQuestInstance.this.doSpawnGroup(
                            L1HardinQuestInstance.this._leader.getLocation(),
                            mobGroupLeaderId, 85 + i);
                    if (i == 1) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$" + 7596, 0)); // 7596 呀！是讴歌！
                    }
                } else {
                    this.cancel();
                }
            } else {
                this.cancel();
            }
        }
    }

    /**
     * 攻击凯尔尼斯.
     */
    class AttackKerenis extends TimerTask {
        /** 随机时间. */
        private int randomtime = 20;

        /**
         * 开始.
         */
        public void begin() {
            final Timer timer = new Timer();
            timer.scheduleAtFixedRate(this, 30 * 1000, this.randomtime * 1000);
        }

        @Override
        public void run() {
            if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) {
                if (L1HardinQuestInstance.this.getBoneLaidStatus() == 0) {
                    final RandomGenerator rd = RandomGeneratorFactory
                            .getSharedRandom();
                    this.randomtime = 20 + rd.nextInt(10);
                    for (final L1Object obj : L1World.getInstance()
                            .getVisibleObjects(
                                    L1HardinQuestInstance.this._Kerenis, 6)) {
                        if (obj instanceof L1MonsterInstance) {
                            if (!((L1MonsterInstance) obj).isDead()) {
                                final L1SkillUse l1skilluse = new L1SkillUse();
                                l1skilluse.handleCommands(
                                        L1HardinQuestInstance.this._leader,
                                        L1SkillId.FROZEN_CLOUD, obj.getId(),
                                        obj.getX(), obj.getY(), null, 0,
                                        L1SkillUse.TYPE_GMBUFF,
                                        L1HardinQuestInstance.this._Kerenis);
                                break;
                            }
                        }
                    }
                } else {
                    this.cancel();
                }
            } else {
                this.cancel();
            }

        }
    }

    /**
     * 召唤炎魔.
     */
    class GuestSpawn extends Thread {
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                final L1Location loc = new L1Location();
                loc.set(32707, 32858, L1HardinQuestInstance.this.getMapId());
                if (L1HardinQuestInstance.this.isHardMode()) {
                    L1NpcInstance Mob = null;
                    if (L1HardinQuestInstance.this.isKerenisAngry()) { // 炎魔
                        Mob = L1HardinQuestInstance.this
                                .spawnOne(loc, 91344, 0);

                        Mob.broadcastPacket(new S_NpcChatPacket(Mob, "$7694", 0)); // 7694 他们果然按计划行动。呵呵..
                        Thread.sleep(1000);
                        Mob.broadcastPacket(new S_NpcChatPacket(Mob, "$7695", 0)); // 7695 是啊，所有的都在他的计划中...
                        Thread.sleep(1000);
                        Mob.broadcastPacket(new S_NpcChatPacket(Mob, "$7709", 0)); // 7709 可能会有很多疑问，但那位魔法师不想给你们时间吧。呵呵..
                        Thread.sleep(1000);
                        L1HardinQuestInstance.this._Hardin
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Hardin,
                                        "$7677", 0)); // 7677 憋住气，赶紧逃脱！肺被那热气融化之前，快！

                    } else {
                        Mob = L1HardinQuestInstance.this
                                .spawnOne(loc, 91343, 0);
                        Mob.broadcastPacket(new S_NpcChatPacket(Mob, "$7663", 0)); // 7663 辛苦了诸位。很大的成果啊。哈哈哈。
                        Thread.sleep(1000);
                        Mob.broadcastPacket(new S_NpcChatPacket(Mob, "$7664", 0)); // 7664 连[凯尔尼斯]也晕过去，很吃惊啊！哈哈哈。
                        Thread.sleep(1000);
                        Mob.broadcastPacket(new S_NpcChatPacket(Mob, "$7665", 0)); // 7665 可能会有很多疑问，但那位魔法师不给你们时间！哈哈哈。
                        Thread.sleep(1000);
                        L1HardinQuestInstance.this._Hardin
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Hardin,
                                        "$7837", 0)); // 7837 大家躲避吧！要封印这地方！
                    }

                    Thread.sleep(1000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$7838", 0)); // 7838 马上要堵南出口，快点出去吧！
                    Thread.sleep(1000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$7839", 0)); // 7839 往东出去的话会有逃脱口！
                }
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 哈丁任务监视器.
     */
    class HardinQuestMonitor extends TimerTask {
        /**
         * 开始.
         */
        public void begin() {
            final Timer timer = new Timer();
            timer.scheduleAtFixedRate(this, 30 * 1000, 300 * 1000);
        }

        /*
         * (non-Javadoc)
         * 
         * @see java.util.TimerTask#run()
         */
        @Override
        public void run() {
            if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) { // 以防万一
                for (final L1PcInstance pc : L1World.getInstance()
                        .getAllPlayers()) {
                    if (L1HardinQuestInstance.this.getMapId() == pc.getMapId()) {
                        return;
                    }
                }
                if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) {
                    L1HardinQuestInstance.this.end();
                }
                this.cancel();
            } else {
                this.cancel();
            }
        }
    }

    /**
     * 线程程序.
     */
    class HqThread extends Thread {

        /*
         * (non-Javadoc)线程程序
         * 
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                L1HardinQuestInstance.this.sendCountDown();
                boolean hardMode = false;
                int pattern = 1;

                if (L1HardinQuestInstance.this.isHardMode()) { // 困难模式
                    hardMode = true;
                }
                for (int round = 1; round <= 12; round++) {
                    // 在开始时验证是否可以继续
                    if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) {
                        L1HardinQuestInstance.this.setCurRound(round);
                        L1HardinQuestInstance.this.sendRoundMessage(round);

                        if ((round > 1) && hardMode) { // 超级困难模式执行中
                            if (L1HardinQuestInstance.this
                                    .getRoundStatus(round - 1) == 1) { // 超级困难
                                pattern = 3;
                            } else {
                                pattern = 2;
                            }
                        }
                        if (round % 4 == 0) { // 只有当一轮BOSS出现时
                            Thread.sleep(5 * 1000);// 暂停5秒
                        }
                        final RandomGenerator random = RandomGeneratorFactory
                                .getSharedRandom();
                        if (99 < (random.nextInt(100) + 1)) {
                            L1HardinQuestInstance.this.setBonusStage(true);
                        }
                        for (int subRound = 1; subRound <= 4; subRound++) {
                            if (L1HardinQuestInstance.this
                                    .isDeleteTransactionNow()) {
                                return;
                            }
                            L1HardinQuestInstance.this
                                    .sendSubRoundMessage(subRound);
                            L1HardinQuestInstance.this.selectSpawn(pattern,
                                    round);
                            // Thread.sleep(9000);
                        }
                        if (round % 4 == 0) {
                            Thread.sleep(109 * 1000);
                        } else {
                            Thread.sleep(75 * 1000);
                        }
                        int cnt = 0;
                        for (final L1PcInstance pc : L1World.getInstance()
                                .getAllPlayers()) {
                            if (pc.getMapId() == L1HardinQuestInstance.this
                                    .getMapId()) {
                                cnt++;
                            }
                        }
                        /*
                         * if (cnt < 5) { //超过5人则不能启动
                         * outPushPlayer(); clearColosseum(); setActive(false);
                         * return; }
                         */
                        if ((L1HardinQuestInstance.this.serchCountMonster() > 4)
                                || L1HardinQuestInstance.this.isBonusStage()) {
                            if (!L1HardinQuestInstance.this.isBonusStage()) {
                                L1HardinQuestInstance.this.sendMessage(7653, 0); // 邪恶的怪物们又来了！准备吧！
                            }
                            Thread.sleep(25 * 1000);
                            if ((L1HardinQuestInstance.this.serchCountMonster() > 4)
                                    || L1HardinQuestInstance.this
                                            .isBonusStage()) {
                                Thread.sleep(35 * 1000);
                                L1HardinQuestInstance.this.sendMessage(7811, 0);
                                L1HardinQuestInstance.this._Hardin
                                        .broadcastPacket(new S_NpcChatPacket(
                                                L1HardinQuestInstance.this._Hardin,
                                                "$7811", 0)); // 7811 这样是完不成任务的！发奋吧！
                                boolean remain = true;
                                for (int i = 0; ((i < 3) && remain)
                                        || L1HardinQuestInstance.this
                                                .isBonusStage(); i++) {
                                    if (L1HardinQuestInstance.this
                                            .isDeleteTransactionNow()) {
                                        return;
                                    }
                                    Thread.sleep(30000);
                                    remain = L1HardinQuestInstance.this
                                            .serchCountMonster() > 4;
                                }

                                if (remain
                                        || L1HardinQuestInstance.this
                                                .isBonusStage()) {
                                    L1HardinQuestInstance.this.sendMessage(
                                            7681, 0);
                                    L1HardinQuestInstance.this._Hardin
                                            .broadcastPacket(new S_NpcChatPacket(
                                                    L1HardinQuestInstance.this._Hardin,
                                                    "$7681", 0)); // 7681 是我过于相信你们了吗...
                                    if (!L1HardinQuestInstance.this
                                            .isDeleteTransactionNow()) {
                                        L1HardinQuestInstance.this
                                                .outPushPlayer(); // end();//
                                    }
                                    // 为确认是否结束 检查每个
                                    return;
                                } else {
                                    L1HardinQuestInstance.this.sendMessage(
                                            8703, 0);
                                    L1HardinQuestInstance.this._Hardin
                                            .broadcastPacket(new S_NpcChatPacket(
                                                    L1HardinQuestInstance.this._Hardin,
                                                    "$8703", 0)); // 8703 哈丁:呼…算是阻止了.加油啊!
                                }
                            }
                            L1HardinQuestInstance.this.setRoundStatus(
                                    round - 1, 2); // 慢
                        } else {
                            L1HardinQuestInstance.this.sendMessage(7652, 0); // 7652 比预想的还要快！小心点！
                            L1HardinQuestInstance.this.setRoundStatus(
                                    round - 1, 1); // 快
                        }
                    } else {
                        return;
                    }
                }
            } catch (final Exception e) {
                _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }
        // 32711 32845 kerenis
        // 32707 32846

    }

    /**
     * 凯尔尼斯部分1.
     */
    class KerenisPart1 extends Thread {
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                final L1Location loc = new L1Location(32742, 32930,
                        L1HardinQuestInstance.this.getMapId());
                L1HardinQuestInstance.this.spawnOne(loc, 91320, 0); // 魔法阵-青(大)
                // 欧林你认为海拉对我有意思吗？
                L1HardinQuestInstance.this._leader
                        .sendPackets(new S_NPCTalkReturn(
                                L1HardinQuestInstance.this._leader.getId(),
                                "j_ep003"));
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$7616", 0)); // 7616 [哈丁]怎么想这天,[奥琳]知道吗?
                L1HardinQuestInstance.this.setActionKerenis(0);
                Thread.sleep(3000);
                if (L1HardinQuestInstance.this.getActionKerenis() == 1) {
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7562", 0)); // 7562 我厉害吧。
                } else {
                    if (L1HardinQuestInstance.this.getActionKerenis() == 2) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7570", 0)); // 7570 给你见识一下？
                    } else { // 0
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7617", 0)); // 7617 [奥琳]...这么快忘记怎么做吗？
                    }
                }

                Thread.sleep(102 * 1000);
                if (L1HardinQuestInstance.this.getSwitchStatus(0) == 0) {
                    L1HardinQuestInstance.this.setSwitchStatus(0, -1);
                }
                // 0＝最后一分钟、1快、2慢
                if (L1HardinQuestInstance.this.isAlreadyFirstSwitch()) {
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7622", 0)); // 7622 开始很顺利吧？以后也拜托了。
                    return;
                } else {
                    // 这么慢，是不是下面的家伙偷懒啊！
                    L1HardinQuestInstance.this._leader
                            .sendPackets(new S_NPCTalkReturn(
                                    L1HardinQuestInstance.this._leader.getId(),
                                    "j_ep004"));
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7618", 0)); // 7618 下面的那些人是傻瓜吗？怎么这么慢！
                    L1HardinQuestInstance.this.setActionKerenis(0); //
                    Thread.sleep(3000);
                    if (L1HardinQuestInstance.this.isAlreadyFirstSwitch()) {
                        L1HardinQuestInstance.this.setSwitchStatus(0, 2);
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7620", 0)); // 咦...是我太急了嘛...感到不好意思啊...’
                    }

                    if (L1HardinQuestInstance.this.getActionKerenis() == 1) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7571", 0)); // 7620 7571 不想想这边情况！
                    } else {
                        if (L1HardinQuestInstance.this.getActionKerenis() == 2) {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7563", 0)); // 7563 呼...夸自己呢?
                        } else {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7619", 0)); // 7619 听懂了给个反映吧！
                        }
                    }
                }
                Thread.sleep(15 * 1000); // 15秒后强制传回
                // -1任务失败
                // System.out.print(getSwitchStatus(0));
                if (L1HardinQuestInstance.this.getSwitchStatus(0) == -1) {
                    if (L1HardinQuestInstance.this.isAlreadyFirstSwitch()) {
                        L1HardinQuestInstance.this.setSwitchStatus(0, 0);
                    } else {
                        if (!L1HardinQuestInstance.this
                                .isDeleteTransactionNow()) {
                            L1HardinQuestInstance.this.outPushPlayer(); // end();
                        }
                    }
                }

            } catch (final InterruptedException ignore) {
            }
        }
    }

    /**
     * 凯尔尼斯部分2.
     * 
     */
    class KerenisPart2 extends Thread {
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                Thread.sleep(310 * 1000);
                if (L1HardinQuestInstance.this.getSwitchStatus(1) == 0) {
                    L1HardinQuestInstance.this.setSwitchStatus(1, -1);
                }
                if (L1HardinQuestInstance.this.isAlreadySecondSwitch()) {
                    return;
                } else {
                    // 这么慢，是不是下面的家伙偷懒啊！
                    L1HardinQuestInstance.this._leader
                            .sendPackets(new S_NPCTalkReturn(
                                    L1HardinQuestInstance.this._leader.getId(),
                                    "j_ep004"));
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7625", 0)); // 7625 下面的那些人肯定是傻瓜！比乌龟还慢的傻瓜！
                    L1HardinQuestInstance.this.setActionKerenis(0);
                    Thread.sleep(3000);
                    if (L1HardinQuestInstance.this.isAlreadySecondSwitch()) {
                        L1HardinQuestInstance.this.setSwitchStatus(1, 2);
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7627", 0)); // 7627 ’呼...这些傻瓜！稍微快点多好！为什么惹我的忍耐心...’
                    }
                    L1HardinQuestInstance.this.setActionKerenis(0);
                    if (L1HardinQuestInstance.this.getActionKerenis() == 1) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7571", 0)); // 7571 不想想这边情况！
                    } else {
                        if (L1HardinQuestInstance.this.getActionKerenis() == 2) {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7563", 0)); // 7563 呼...夸自己呢?
                        } else {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7626", 0)); // 7626 女人发火的时候！最好给点反映！
                        }
                    }
                }
                Thread.sleep(15 * 1000);// 15秒后强制传回
                // -1任务失败
                if (L1HardinQuestInstance.this.getSwitchStatus(1) == -1) {
                    if (L1HardinQuestInstance.this.isAlreadySecondSwitch()) {
                        L1HardinQuestInstance.this.setSwitchStatus(1, 0);
                    } else {
                        if (!L1HardinQuestInstance.this
                                .isDeleteTransactionNow()) {
                            L1HardinQuestInstance.this.outPushPlayer(); // end();
                        }
                    }
                }
            } catch (final InterruptedException ignore) {
            }
        }
    }

    /**
     * 凯尔尼斯部分3.
     */
    class KerenisPart3 extends Thread {
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                Thread.sleep(230 * 1000);
                if (L1HardinQuestInstance.this.getSwitchStatus(2) == 0) {
                    L1HardinQuestInstance.this.setSwitchStatus(2, -1);
                }
                if (L1HardinQuestInstance.this.isAlreadyPortal()) {
                    return;
                } else {
                    // 这么慢，是不是下面的家伙偷懒啊！
                    L1HardinQuestInstance.this._leader
                            .sendPackets(new S_NPCTalkReturn(
                                    L1HardinQuestInstance.this._leader.getId(),
                                    "j_ep004"));
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7632", 0)); // 7632 啊！你们是些任性的傻瓜！
                    L1HardinQuestInstance.this.setActionKerenis(0);
                    Thread.sleep(3000);
                    if (L1HardinQuestInstance.this.isAlreadyPortal()) {
                        L1HardinQuestInstance.this.setSwitchStatus(2, 2);
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7634", 0)); // 7634 ’觉得我更任性嘛...’
                    }

                    if (L1HardinQuestInstance.this.getActionKerenis() == 1) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7563", 0)); // 7563 呼...夸自己呢?
                    } else {
                        if (L1HardinQuestInstance.this.getActionKerenis() == 2) {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7571", 0)); // 7620 7571 不想想这边情况！
                        } else {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7633", 0)); // 7633 [奥琳]，你！！
                        }
                    }
                }
                Thread.sleep(15 * 1000);// 15秒后强制传回
                // -1任务失败
                if (L1HardinQuestInstance.this.getSwitchStatus(2) == -1) {
                    if (L1HardinQuestInstance.this.isAlreadyPortal()) {
                        L1HardinQuestInstance.this.setSwitchStatus(2, 0);
                    } else {
                        if (!L1HardinQuestInstance.this
                                .isDeleteTransactionNow()) {
                            L1HardinQuestInstance.this.outPushPlayer(); // end();
                        }
                    }
                }
            } catch (final InterruptedException ignore) {
            }
        }
    }

    /**
     * 凯尔尼斯部分4.
     */
    class KerenisPart4 extends Thread {
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                Thread.sleep(150 * 1000);
                if (L1HardinQuestInstance.this.getSwitchStatus(3) == 0) {
                    L1HardinQuestInstance.this.setSwitchStatus(3, -1);
                }
                if (L1HardinQuestInstance.this.isAlreadyGuardManDeath()) {
                    return;
                } else {
                    // 这么慢，是不是下面的家伙偷懒啊！
                    L1HardinQuestInstance.this._leader
                            .sendPackets(new S_NPCTalkReturn(
                                    L1HardinQuestInstance.this._leader.getId(),
                                    "j_ep004"));
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7640", 0)); // 7640 说明你们是不能救世？！
                    L1HardinQuestInstance.this.setActionKerenis(0);
                    Thread.sleep(3000);
                    if (L1HardinQuestInstance.this.isAlreadyGuardManDeath()) {
                        L1HardinQuestInstance.this.setSwitchStatus(3, 2);
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7642", 0)); // 7642 “这些傻瓜是逼我发火！嗨！”
                    }

                    if (L1HardinQuestInstance.this.getActionKerenis() == 1) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7563", 0)); // 7563 呼...夸自己呢?
                    } else {
                        if (L1HardinQuestInstance.this.getActionKerenis() == 2) {
                            L1HardinQuestInstance.this._Kerenis
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Kerenis,
                                            "$7571", 0)); // 7620 7571 不想想这边情况！
                        }
                    }
                    Thread.sleep(3000);
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7641", 0)); // 7641 呼...好吧...算是吧...
                }
                Thread.sleep(15 * 1000);// 15秒后强制传回
                // -1任务失败
                if (L1HardinQuestInstance.this.getSwitchStatus(3) == -1) {
                    if (L1HardinQuestInstance.this.isAlreadyGuardManDeath()) {
                        L1HardinQuestInstance.this.setSwitchStatus(3, 0);
                    } else {
                        if (!L1HardinQuestInstance.this
                                .isDeleteTransactionNow()) {
                            L1HardinQuestInstance.this.outPushPlayer(); // end();
                        }
                    }
                }
            } catch (final InterruptedException ignore) {
            }
        }
    }

    /**
     * 凯尔尼斯随机说话.
     */
    class KerenisRandomMessage extends TimerTask {
        /** 系统信息. */
        private static final int MSGID = 7576;

        /** 开始. */
        public void begin() {
            final Timer timer = new Timer();
            timer.scheduleAtFixedRate(this, 10 * 1000, 60 * 1000);
        }

        /*
         * 7576 这到底是有什么意义的事情呢？
         * 7577 使用[治愈:毒药]能把妖魔弄白!
         * 7578 母亲名字是[伊娃]...但父亲名字是...
         * 7579 我有喜欢的人，至于谁是秘密，哈哈。
         * 7580 我命令你出来吧[魔法珠！]，呵呵...还是不行^^
         * 7581 生命之水啊！时间之风啊！请让我[成熟]吧！...唉...就知道会这样^^;;
         * 7582 我不喜欢甜的。但...血腥味...
         * 7583 [伊娃]的女儿是不会觉得渴。
         * 7584 我不怕火!绝对!
         * 7585 有没有能让我开心的方法呢?
         * 7586 呼...过了今天，又会到没意义的今天吧？以明天的名字...
         * 7587 把[妖魔]消灭掉！
         */
        @Override
        public void run() {
            if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) {
                final RandomGenerator rd = RandomGeneratorFactory
                        .getSharedRandom();
                final int i = rd.nextInt(12);
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$"
                                        + (MSGID + i), 0));
            } else {
                this.cancel();
            }
        }
    }

    /**
     * 移动黑墙(将在几秒钟内打开).
     */
    class MoveWall extends TimerTask {
        /** 随机值. */
        private final RandomGenerator rnd = RandomGeneratorFactory.newRandom();

        /** 开始. */
        public void begin() {
            final Timer timer = new Timer();
            timer.schedule(this, 3 * 1000);
        }

        /**
         * 查找坐标位置.
         * 
         * @param base
         *            - 坐标位置
         * @return 坐标位置
         */
        private L1Location findLocation(final L1Location base) {
            final L1Location newLoc = new L1Location(base);
            boolean find = true;
            while (find) {
                find = false;
                final int moveX = 2 + this.rnd.nextInt(3); // 前方2~4格
                final int moveY = this.rnd.nextInt(7); // 左端相对7格
                newLoc.set(newLoc.getX() + moveX, newLoc.getY() - moveY);
                for (final L1Object obj : L1World.getInstance()
                        .getVisiblePoint(newLoc, 0)) {
                    if (!(obj instanceof L1ItemInstance)) {
                        find = true;
                        break;
                    }
                }
            }
            return newLoc;
        }

        @Override
        public void run() {
            try {
                for (final L1DoorInstance wall : Lists
                        .newArrayList(L1HardinQuestInstance.this.getAllDoors())) {
                    final L1Location newLoc = this.findLocation(wall
                            .getLocation());
                    L1HardinQuestInstance.this.removeDoor(wall);
                    L1HardinQuestInstance.this.addDoor(newLoc);
                    Thread.sleep(600);
                }
                Thread.sleep(5000);
                // 启动关门模式 1:左、2:右
                int val;
                int startX1; // 32703,32702
                int startX2;
                // int frontY;32866 10
                // int backY;872 7
                if (this.rnd.nextInt(2) == 0) { // 1
                    val = 1;
                    startX1 = 32703;
                    startX2 = startX1;
                } else {
                    val = -1;
                    startX1 = 32711;
                    startX2 = 32709;
                }
                int cnt = 0;
                for (final L1DoorInstance wall : Lists
                        .newArrayList(L1HardinQuestInstance.this.getAllDoors())) {
                    final L1Location newLoc = new L1Location();
                    if (cnt % 2 == 0) {
                        newLoc.set(startX1, 32866,
                                L1HardinQuestInstance.this.getMapId());
                        startX1 += val;
                    } else {
                        newLoc.set(startX2, 32872,
                                L1HardinQuestInstance.this.getMapId());
                        startX2 += val;
                    }
                    this.waitForLocation(newLoc);
                    L1HardinQuestInstance.this.removeDoor(wall);
                    L1HardinQuestInstance.this.addDoor(newLoc);
                    Thread.sleep(600);
                    cnt++;
                }
                Thread.sleep(20000);
                // 8718 中间的脚板只能启动一次,注意点.
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$8718", 0));// ブルー
            } catch (final InterruptedException e) {
                _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }

        }

        /**
         * 等待的坐标位置.
         * 
         * @param loc
         *            - 坐标位置
         * @throws InterruptedException
         *             -
         */
        private void waitForLocation(final L1Location loc)
                throws InterruptedException {
            boolean find = true;
            while (find) {
                find = false;
                for (final L1Object obj : L1World.getInstance()
                        .getVisiblePoint(loc, 0)) {
                    if (!(obj instanceof L1ItemInstance)) {
                        find = true;
                        Thread.sleep(500);
                        break;
                    }
                }
            }
        }

    }

    /**
     * 妖魔说话.
     */
    class OrcVocabulary extends TimerTask {
        /**
         * 开始.
         */
        public void begin() {
            final Timer timer = new Timer();
            timer.schedule(this, 2 * 1000);
        }

        /*
         * 7842 那魔魔魔..魔女...我...口..口吃..
         * 7848 是谁打了魔女。
         * 7854　别站出去！
         * 7849 对不起..
         * 7855 要惩罚我们魔女吗！
         * 7843 我..我我。我..魔女..害害害..害怕...
         * 7856 [阀芯]臭小子！你在这等！
         * 7844 [阀芯]对..对..对不起。
         * 7857 联系朋友了吗？
         * 7851 联系了。马上就到。
         * 7858 等朋友们来之前我们在这看动静！
         * 7852 队长，我们也害怕了？
         * 7859 算了吧！聪明的我有战略！
         * 7853 再次对不起..
         * 7850 我不站出去。
         * 7845 魔女..害害害..害怕...
         * 7846 但..但。但是..什什..什么时候去？
         * 7847 我害怕。不不不...不不能再等了...
         */
        @Override
        public void run() {
            try {
                final L1Location loc = new L1Location();
                loc.set(32746, 32932, L1HardinQuestInstance.this.getMapId());
                final L1NpcInstance orc = L1HardinQuestInstance.this.spawnOne(
                        loc, 91333, 7); // 妖魔
                loc.set(32748, 32931, L1HardinQuestInstance.this.getMapId());
                final L1NpcInstance orcFighter = L1HardinQuestInstance.this
                        .spawnOne(loc, 91336, 7); // 妖魔斗士
                loc.set(32745, 32935, L1HardinQuestInstance.this.getMapId());
                final L1NpcInstance orcArcher = L1HardinQuestInstance.this
                        .spawnOne(loc, 91334, 7); // 妖魔弓箭手
                loc.set(32747, 32934, L1HardinQuestInstance.this.getMapId());
                final L1NpcInstance barusim = L1HardinQuestInstance.this
                        .spawnOne(loc, 91335, 7); // 巴辛
                Thread.sleep(2000);
                barusim.broadcastPacket(new S_NpcChatPacket(barusim, "$7842", 0)); // 7842 那魔魔魔..魔女...我...口..口吃..
                Thread.sleep(2000);
                orc.broadcastPacket(new S_NpcChatPacket(orc, "$7848", 0)); // 7848 是谁打了魔女。
                Thread.sleep(2000);
                orcFighter.broadcastPacket(new S_NpcChatPacket(orcFighter,
                        "$7854", 0)); // 7854　别站出去！
                Thread.sleep(2000);
                orc.broadcastPacket(new S_NpcChatPacket(orc, "$7849", 0)); // 7849 对不起..
                Thread.sleep(2000);
                orcFighter.broadcastPacket(new S_NpcChatPacket(orcFighter,
                        "$7855", 0)); // 7855 要惩罚我们魔女吗！
                Thread.sleep(2000);
                barusim.broadcastPacket(new S_NpcChatPacket(barusim, "$7843", 0)); // 7843 我..我我。我..魔女..害害害..害怕...
                Thread.sleep(2000);
                orcFighter.broadcastPacket(new S_NpcChatPacket(orcFighter,
                        "$7856", 0)); // 7856 [阀芯]臭小子！你在这等！
                Thread.sleep(2000);
                barusim.broadcastPacket(new S_NpcChatPacket(barusim, "$7844", 0)); // 7844 [阀芯]对..对..对不起。
                Thread.sleep(2000);
                orcFighter.broadcastPacket(new S_NpcChatPacket(orcFighter,
                        "$7857", 0)); // 7857 联系朋友了吗？
                Thread.sleep(2000);
                orcArcher.broadcastPacket(new S_NpcChatPacket(orcArcher,
                        "$7851", 0)); // 7851 联系了。马上就到。
                Thread.sleep(2000);
                orcFighter.broadcastPacket(new S_NpcChatPacket(orcFighter,
                        "$7858", 0)); // 7858 等朋友们来之前我们在这看动静！
                Thread.sleep(2000);
                orcArcher.broadcastPacket(new S_NpcChatPacket(orcArcher,
                        "$7852", 0)); // 7852 队长，我们也害怕了？
                Thread.sleep(2000);
                orcFighter.broadcastPacket(new S_NpcChatPacket(orcFighter,
                        "$7859", 0)); // 7859 算了吧！聪明的我有战略！
                Thread.sleep(2000);
                // 出口 32748 32935
                while (orcFighter.moveDirection(32748, 32935) != -1) {
                    if (orcFighter.getLocation().getLineDistance(
                            new Point(32748, 32935)) != 0) {
                        orcFighter.setDirectionMove(orcFighter.moveDirection(
                                32748, 32935));
                        Thread.sleep(orcFighter.getPassispeed());
                    } else {
                        break;
                    }
                }
                Thread.sleep(2000);
                orcFighter.deleteMe();

                orcArcher.broadcastPacket(new S_NpcChatPacket(orcArcher,
                        "$7853", 0)); // 7853 再次对不起..
                Thread.sleep(2000);
                while (orcArcher.moveDirection(32748, 32935) != -1) {
                    if (orcArcher.getLocation().getLineDistance(
                            new Point(32748, 32935)) != 0) {
                        orcArcher.setDirectionMove(orcArcher.moveDirection(
                                32748, 32935));
                        Thread.sleep(orcArcher.getPassispeed());
                    } else {
                        break;
                    }
                }
                Thread.sleep(2000);
                orcArcher.deleteMe();

                orc.broadcastPacket(new S_NpcChatPacket(orc, "$7850", 0)); // 7850 我不站出去。
                Thread.sleep(2000);
                while (orc.moveDirection(32748, 32935) != -1) {
                    if (orc.getLocation().getLineDistance(
                            new Point(32748, 32935)) != 0) {
                        orc.setDirectionMove(orc.moveDirection(32748, 32935));
                        Thread.sleep(orc.getPassispeed());
                    } else {
                        break;
                    }
                }
                Thread.sleep(2000);
                orc.deleteMe();

                barusim.broadcastPacket(new S_NpcChatPacket(barusim, "$7845", 0)); // 7845 魔女..害害害..害怕...
                Thread.sleep(4000);
                barusim.broadcastPacket(new S_NpcChatPacket(barusim, "$7846", 0)); // 7846 但..但。但是..什什..什么时候去？
                Thread.sleep(4000);
                barusim.broadcastPacket(new S_NpcChatPacket(barusim, "$7847", 0)); // 7847 我害怕。不不不...不不能再等了...
                Thread.sleep(2000);
                while (barusim.moveDirection(32748, 32935) != -1) {
                    if (barusim.getLocation().getLineDistance(
                            new Point(32748, 32935)) != 0) {
                        barusim.setDirectionMove(barusim.moveDirection(32748,
                                32935));
                        Thread.sleep(barusim.getPassispeed());
                    } else {
                        break;
                    }
                }
                Thread.sleep(2000);
                barusim.deleteMe();

            } catch (final InterruptedException e) {

                e.printStackTrace();
            }

        }
    }

    /**
     * 初始任务开始(倒计时).
     */
    class Preliminary extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7598", 0)); // 7598 来了？稍等，需要准备一下。4
                Thread.sleep(4000);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$8693", 0)); // 8693 那开始最终检验吧?8
                Thread.sleep(8000);
                L1HardinQuestInstance.this.setActionHardin(0);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$8694", 0)); // 8694 不需要最终检验就按[alt+2].8
                Thread.sleep(8000);
                if (L1HardinQuestInstance.this.getActionHardin() != 1) {
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8695", 0)); // 8695 进入宫殿,会接受资格试验的.
                    Thread.sleep(8000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8696", 0)); // 8696 对手不是很强,相信你们能通过.
                    Thread.sleep(8000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8697", 0)); // 8697 然后为你们准备了可以解除或设置陷阱的脚板.
                    Thread.sleep(8000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8698", 0)); // 8698 虽然让你们容易看到脚板..
                    Thread.sleep(8000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8699", 0)); // 8699 以我的味觉就不需要工具了.
                    Thread.sleep(8000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8700", 0)); // 8700 此外还有可期待的,但时间问题赶紧吧.
                    Thread.sleep(8000);
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$8701", 0)); // 8701 小心点吧!安全是无法保障的.
                    Thread.sleep(8000);
                }
                L1HardinQuestInstance.this.setActionHardin(0);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$8702", 0)); // 8702 那开始吧?
                Thread.sleep(4000);
                if (L1HardinQuestInstance.this.getActionHardin() != 1) {
                    // 欧林，时间不多了。再给你10秒钟
                    L1HardinQuestInstance.this._leader
                            .sendPackets(new S_NPCTalkReturn(
                                    L1HardinQuestInstance.this._leader.getId(),
                                    "j_ep002"));
                    Thread.sleep(10000);
                }

                L1HardinQuestInstance.this.setActionHardin(0); // 初始化
                // 才来吗？欧林，出发前给你时间寒暄。按[alt + 2]是寒暄语。
                L1HardinQuestInstance.this._leader
                        .sendPackets(new S_NPCTalkReturn(
                                L1HardinQuestInstance.this._leader.getId(),
                                "j_ep001"));
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7599", 0)); // 7599 [奥琳]是道别语,按[alt+2]就行了。
                Thread.sleep(8000);
                if (L1HardinQuestInstance.this.getActionHardin() != 1) {
                    L1HardinQuestInstance.this._Hardin
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Hardin,
                                    "$7601", 0)); // 7601 [奥琳]再给你5秒道别时间。
                    L1HardinQuestInstance.this.setActionHardin(0); // 初始化
                    Thread.sleep(10000);
                    for (int i = 0; i < 5; i++) { // 5次等待时间
                        if (L1HardinQuestInstance.this.getActionHardin() != 1) {
                            L1HardinQuestInstance.this.setActionHardin(0); // 初始化
                            L1HardinQuestInstance.this._Hardin
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Hardin,
                                            "$7602", 0)); // 7602 [奥琳]不能再等了。
                            Thread.sleep(8000);
                        } else {
                            break;
                        }
                    }
                }
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7600", 0)); // 7600 是啊，[奥琳]准备好了吧。
                Thread.sleep(8000);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7603", 0)); // 7603 [奥琳]现在送到凯尔尼斯那。
                Thread.sleep(2000);
                // 传送 0 ,47 s
                if (L1HardinQuestInstance.this._leader.getMapId() == L1HardinQuestInstance.this
                        .getMapId()) {
                    L1Teleport.teleport(L1HardinQuestInstance.this._leader,
                            32738, 32930,
                            L1HardinQuestInstance.this.getMapId(), 5, true);
                }
                final L1Location loc = new L1Location();
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7604", 0)); // 7604 好吧！剩下的人也准备出发吧。
                /* 1 */
                Thread.sleep(1000);
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$7607", 0)); // 7607 果然，[奥琳]来了。
                /* 5 */
                Thread.sleep(4000);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7605", 0)); // 7605 赶紧，魔法阵会马上消失的。
                /* 10 */
                Thread.sleep(2000);
                // 魔法阵出现
                loc.set(32725, 32724, L1HardinQuestInstance.this.getMapId());
                L1HardinQuestInstance.this.setSwitch(loc, 65);
                L1HardinQuestInstance.this.spawnOne(loc, 91319, 0);
                /* 12 */
                Thread.sleep(5000);
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7606", 0)); // 7606 我先到目的地了。
                Thread.sleep(4000);
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$7608", 0)); // 7608 你的职责是保护我。归根结底没有别的事情做，意思就是[奥琳]会很快腻味的。
                Thread.sleep(4000);
                /* 20 */
                // ハーディンテレポート
                L1HardinQuestInstance.this._Hardin.teleport(32716, 32846, 6);
                loc.set(32716, 32846, L1HardinQuestInstance.this.getMapId());
                L1HardinQuestInstance.this.spawnOne(loc, 91319, 0);
                L1HardinQuestInstance.this.spawnOne(loc, 91317, 0);
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$7609", 0)); // 7609 这期间会无聊，听我给你讲。
                Thread.sleep(5000);
                L1HardinQuestInstance.this.setActionKerenis(0);
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$7610", 0)); // 7610 对于我的话使用[alt+2]确定或[alt+4]否定来表示。明白了吗？
                Thread.sleep(5000);
                /* 30 */// 这里很危险
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7611", 0)); // 7611 这地方危险，希望设些装置不要让其他人接近。
                Thread.sleep(2000);
                if (L1HardinQuestInstance.this.getActionKerenis() == 1) {
                    L1HardinQuestInstance.this._Kerenis
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7561", 0)); // 7561 恩，就那么做。
                } else {
                    if (L1HardinQuestInstance.this.getActionKerenis() == 2) {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7569", 0)); // 7569 那是什么意思！
                    } else {
                        L1HardinQuestInstance.this._Kerenis
                                .broadcastPacket(new S_NpcChatPacket(
                                        L1HardinQuestInstance.this._Kerenis,
                                        "$7612", 0)); // 7612 理解的话，给个反映吧！
                    }
                }
                Thread.sleep(5000);
                /* 37 */// 只有你们能看见装置
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7613", 0)); // 7613 只有你们能看见装置，希望好好做。
                Thread.sleep(2000);
                L1HardinQuestInstance.this._Kerenis
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Kerenis, "$7614", 0)); // 7614 那现在开始进主题吧。
                L1HardinQuestInstance.this._Hardin
                        .broadcastPacket(new S_NpcChatPacket(
                                L1HardinQuestInstance.this._Hardin, "$7615", 0)); // 7615 那赶紧把事情做完到这边吧。
                Thread.sleep(2000);
                /* 41 */// 门开启--到这里初步处理完成
                /* 启动计时器和线程 */
                if (!L1HardinQuestInstance.this.isDeleteTransactionNow()) {
                    L1HardinQuestInstance.this._kp1 = new KerenisPart1();
                    GeneralThreadPool.getInstance().execute(
                            L1HardinQuestInstance.this._kp1);
                    L1HardinQuestInstance.this._krm = new KerenisRandomMessage();
                    L1HardinQuestInstance.this._krm.begin();
                }
            } catch (final InterruptedException e) {

                e.printStackTrace();
            }
        }
    }

    /**
     * 召唤BOSS.
     */
    class SpawnBoss extends TimerTask {
        /**
         * 开始.
         */
        public void begin() {
            final Timer timer = new Timer();
            timer.schedule(this, 0);
        }

        /*
         * 7655 巴风特
         * 7656 谁叫我了！！！
         * 7657 呵呵...[哈丁]是你吗！哈哈哈！
         * 7658 这是什么！都意思嘛！？
         * 7659 [凯尔尼斯]终于来了！
         * 7660 不...不是！[凯尔尼斯]怎么了！[奥琳]发生什么事了吧?
         */
        @Override
        public void run() {
            try {
                if (L1HardinQuestInstance.this.getCurRound() == 4) {
                    L1HardinQuestInstance.this.spawnOneMob(
                            L1HardinQuestInstance.this.getLocation(), 91291); // 死亡骑士
                } else if (L1HardinQuestInstance.this.getCurRound() == 8) {
                    L1HardinQuestInstance.this.spawnOneMob(
                            L1HardinQuestInstance.this.getLocation(), 91293); // 不死鸟
                } else if (L1HardinQuestInstance.this.getCurRound() == 12) {
                    int cnt = 0;
                    for (int i = 0; i < L1HardinQuestInstance.this._roundStatus.length; i++) {
                        if (L1HardinQuestInstance.this.getRoundStatus(i) == 1) {
                            cnt++;
                        }
                    }
                    L1MonsterInstance Kerenis = null;
                    if (8 < cnt) { // 至少9次以上 巴风特出现、否则为死神
                        L1HardinQuestInstance.this._lunker = L1HardinQuestInstance.this
                                .spawnOneMob(L1HardinQuestInstance.this
                                        .getLocation(), 91294); // 巴风特
                    } else {
                        L1HardinQuestInstance.this._lunker = L1HardinQuestInstance.this
                                .spawnOneMob(L1HardinQuestInstance.this
                                        .getLocation(), 91290); // 镰刀死神的使者
                    }
                    final L1Location loc = new L1Location(32711, 32845,
                            L1HardinQuestInstance.this.getMapId());
                    boolean kerenisSpawn = true;

                    /*
                     * 7656 谁叫我了！！！
                     * 7657 呵呵...[哈丁]是你吗！哈哈哈！
                     */
                    L1HardinQuestInstance.this._lunker
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._lunker,
                                    "$7656", 0));
                    Thread.sleep(1000);
                    L1HardinQuestInstance.this._lunker
                            .broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._lunker,
                                    "$7657", 0));
                    if (!L1HardinQuestInstance.this.isKerenisAngry()) { // 愤怒的凯尔尼斯
                        Kerenis = L1HardinQuestInstance.this.spawnOneMob(loc,
                                91296);
                    } else { // 黑翼赛尼斯
                        if (L1HardinQuestInstance.this.isHardMode()
                                && (L1HardinQuestInstance.this
                                        .getBoneLaidStatus() == 2)) {
                            Kerenis = L1HardinQuestInstance.this.spawnOneMob(
                                    loc, 91295);
                        } else {
                            kerenisSpawn = false;
                        }
                    }
                    if (kerenisSpawn) {
                        Kerenis.tagertClear();
                        Kerenis.setTarget(L1HardinQuestInstance.this._lunker);
                        L1HardinQuestInstance.this._lunker.tagertClear();
                        L1HardinQuestInstance.this._lunker.setTarget(Kerenis);
                        if (Kerenis.getNpcId() == 91296) { // 愤怒的赛尼斯
                            /*
                             * 7820 不好意思，来晚了.
                             * 7821 [凯尔尼斯]拉住那个魔物的注意吧！
                             * 7822 我明白了!你知道这不是件容易的事情吧?
                             * 7823 [哈丁！]释放我的力量，后果不堪设想的！
                             * 7824 [凯尔尼斯]后面交给我就行了。
                             */
                            Kerenis.broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7820", 0));
                            Thread.sleep(1500);
                            L1HardinQuestInstance.this._Hardin
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Hardin,
                                            "$7821", 0));
                            Thread.sleep(1500);
                            Kerenis.broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7822", 0));
                            Thread.sleep(1500);
                            Kerenis.broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7823", 0));
                            Thread.sleep(1500);
                            L1HardinQuestInstance.this._Hardin
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Hardin,
                                            "$7824", 0));
                        } else { // 黑翼赛尼斯
                            /*
                             * 7815 [奥琳！]现在是处置你的时间！
                             * 7816 这是什么!谁动了我的食物!
                             * 7817 [奥琳！]出什么事情了！
                             * 7818 先给你做料理!
                             * 7819 这个臭丫头!
                             */
                            Kerenis.broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7815", 0));
                            Thread.sleep(1500);
                            Kerenis.broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7816", 0));
                            Thread.sleep(1500);
                            L1HardinQuestInstance.this._Hardin
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._Hardin,
                                            "$7817", 0));
                            Thread.sleep(1500);
                            Kerenis.broadcastPacket(new S_NpcChatPacket(
                                    L1HardinQuestInstance.this._Kerenis,
                                    "$7818", 0));
                            Thread.sleep(1500);
                            L1HardinQuestInstance.this._lunker
                                    .broadcastPacket(new S_NpcChatPacket(
                                            L1HardinQuestInstance.this._lunker,
                                            "$7819", 0));
                            Thread.sleep(1500);
                        }
                    }
                }
            } catch (final InterruptedException e) {

                e.printStackTrace();
            }
        }
    }

    /** 中心点. */
    private L1Location _location;
    /** 地图编号. */
    private short _mapId;
    /** 队长. */
    private L1PcInstance _leader;
    /** 随机符文效果. */
    private int[] _randomRuneEffect;
    /** 一轮状态. */
    private int[] _roundStatus;
    /** 开关状态. */
    private int[] _switchStatus;
    /** 哈丁. */
    private L1NpcInstance _Hardin;
    /** 凯尔尼斯. */
    private L1NpcInstance _Kerenis;
    /** 主动. */
    private boolean _active;
    /** 接收的所有动作. */
    private boolean _receiveAllAction;
    /** 愤怒的凯尔尼斯. */
    private boolean _kerenisAngry;
    /** 提示信息. */
    private static final Logger _log = Logger
            .getLogger(L1HardinQuestInstance.class.getName());

    // private final ArrayList<L1PcInstance> _members = new
    // ArrayList<L1PcInstance>();
    /** 已有的第一个开关. */
    private boolean _alreadyFirstSwitch;
    /** 已有的第二个开关. */
    private boolean _alreadySecondSwitch;
    /** 已有的入口. */
    private boolean _alreadyPortal;
    /** 已有的提示. */
    private boolean _hintAlready;
    /** 当前回合. */
    private int _curRound;
    /** 召唤BOSS. */
    SpawnBoss _sb;
    /** 线程程序. */
    HqThread _hq;
    /** 初始任务开始(倒计时). */
    Preliminary _preliminary;
    /** 哈丁任务监视器. */
    HardinQuestMonitor _hqm;
    /** 凯尔尼斯随机说话. */
    KerenisRandomMessage _krm;
    /** 凯尔尼斯部分1. */
    KerenisPart1 _kp1;
    /** 凯尔尼斯部分2. */
    KerenisPart2 _kp2;
    /** 凯尔尼斯部分3. */
    KerenisPart3 _kp3;
    /** 凯尔尼斯部分4. */
    KerenisPart4 _kp4;
    /** 召唤袭击者. */
    AssailantSpawn _as;
    /** 攻击凯尔尼斯. */
    AttackKerenis _ak;
    /** 踩踏出的已有符文. */
    private boolean _BlackRuneTrodAlready;
    /** 妖魔说话. */
    OrcVocabulary _ov;
    /** 黑色符文. */
    private boolean _blackRune;
    /** 凯尔尼斯动作. */
    private int _actionKerenis;
    /** 哈丁动作. */
    private int _actionHardin;
    /** 玩家名单. */
    private int[] _onPlayerList;
    /** . */
    L1NpcInstance _lunker;
    /** 已有的队员死亡者. */
    private boolean _alreadyGuardManDeath;
    /** 立即删除事物. */
    private boolean _deleteTransactionNow;
    /** 陷阱集合列表. */
    private final ArrayList<L1TrapInstance> _trapList = new ArrayList<L1TrapInstance>();
    /** 门集合列表. */
    private ArrayList<L1DoorInstance> _doors;
    /** 移动黑墙(将在几秒钟内打开). */
    MoveWall _mw;
    /** 黑墙的图形编号. */
    private static final int WALL_GFXID = 7536;
    /** 黑墙的图形. */
    private final L1DoorGfx _wallGfx = L1DoorGfx.findByGfxId(WALL_GFXID);
    /** 召唤炎魔. */
    GuestSpawn _gs;
    /** 奖励阶段. */
    private boolean _bonusStage;

    /**
     * 哈丁副本控制项.
     * 
     * @param mapId
     *            - 地图编号
     */
    public L1HardinQuestInstance(final short mapId) {
        this.setMapId(mapId);
        this.init();
    }

    /**
     * 增加门.
     * 
     * @param loc
     *            - 坐标点
     */
    private void addDoor(final L1Location loc) {
        // XXX keeperId = 1防止开启或关闭。
        final L1DoorInstance door = DoorTable.getInstance().createDoor(0,
                this._wallGfx, loc, 0, 1);
        this.getAllDoors().add(door);
    }

    /**
     * 增加进陷阱列表.
     * 
     * @param trap
     *            - 陷阱
     */
    private void addTrapList(final L1TrapInstance trap) {
        this._trapList.add(trap);
    }

    // XXX for ClientThread.java
    /**
     * 检查离开游戏.
     * 
     * @param pc
     *            - 对象
     */
    public void checkLeaveGame(final L1PcInstance pc) {
        // 反馈处理
        if (pc.getMapId() == this.getMapId()) {
            final RandomGenerator random = RandomGeneratorFactory
                    .getSharedRandom();
            final int rndx = random.nextInt(4);
            final int rndy = random.nextInt(4);
            final int locx = 32587 + rndx;
            final int locy = 32941 + rndy;
            final short mapid = 0;
            L1Teleport.teleport(pc, locx, locy, mapid, 5, false);
        }
    }

    /**
     * 创造黑墙.
     */
    private void createWalls() {
        for (int i = 0; i < 10; i++) {
            // 前方
            this.addDoor(new L1Location(32702 + i, 32866, this.getMapId()));
            // 后方
            this.addDoor(new L1Location(32703 + i, 32872, this.getMapId()));
        }
    }

    /**
     * 召唤群组.
     * 
     * @param loc
     *            - 坐标位置
     * @param npcId
     *            - NPC编号
     * @param groupId
     *            - 群组编号
     */
    private void doSpawnGroup(final L1Location loc, final int npcId,
            final int groupId) {
        final L1NpcInstance mob = new L1NpcInstance(NpcTable.getInstance()
                .getTemplate(npcId));

        mob.setId(IdFactory.getInstance().nextId());
        mob.setHeading(5);
        mob.setX(loc.getX());
        mob.setHomeX(loc.getX());
        mob.setY(loc.getY());
        mob.setHomeY(loc.getY());
        mob.setMap((short) loc.getMapId());
        L1MobGroupSpawn.getInstance().doSpawn(mob, groupId, true, false);
        mob.deleteMe();
    }

    /**
     * 结束.
     */
    public void end() {
        // this.outPushPlayer(); // 强制玩家传出地图。
        this.setDeleteTransactionNow(true); // 开始删除
        this.killTimer(); // 结束所有的等待线程和定时器
        this.reset(); // 保存并删除map上的对象
        this.setDeleteTransactionNow(false); // 删除结束
        // 删除打开的新地图
        L1HardinQuest.getInstance().resetActiveMaps(this.getMapId());
    }

    /**
     * 取得哈丁动作.
     * 
     * @return 哈丁动作
     */
    private int getActionHardin() {
        return this._actionHardin;
    }

    /**
     * 取得凯尔尼斯动作.
     * 
     * @return 凯尔尼斯动作
     */
    private int getActionKerenis() {
        return this._actionKerenis;
    }

    /**
     * 从集合中取得所有门.
     * 
     * @return 列表中的门
     */
    private ArrayList<L1DoorInstance> getAllDoors() {
        return this._doors;
    }

    /**
     * 取得Bone闲置状态.
     * 
     * @return 闲置状态(1:快、２:慢)
     */
    private int getBoneLaidStatus() { // 1:快、２:慢
        return this.getSwitchStatus(this._switchStatus.length - 1);
    }

    /**
     * 取得当前回合.
     * 
     * @return 当前回合
     */
    private int getCurRound() {
        return this._curRound;
    }

    /**
     * 取得中心点.
     * 
     * @return 中心点
     */
    L1Location getLocation() {
        return this._location;
    }

    /**
     * 取得地图编号.
     * 
     * @return 地图编号
     */
    public short getMapId() {
        return this._mapId;
    }

    /**
     * 取得玩家名单.
     * 
     * @return 玩家名单
     */
    private int[] getOnPlayerList() {
        return this._onPlayerList;
    }

    /**
     * 取得随机符文效果.
     * 
     * @param i
     *            - 效果
     * @return 效果
     */
    private int getRandomRuneEffect(final int i) {
        return this._randomRuneEffect[i];
    }

    /**
     * 取得接受的所有动作.
     * 
     * @return 接受的所有动作
     */
    private boolean getReceiveAllAction() {
        return this._receiveAllAction;
    }

    /**
     * 取得一轮状态.
     * 
     * @param i
     *            - 状态
     * @return 一轮状态
     */
    private int getRoundStatus(final int i) {
        return this._roundStatus[i];
    }

    /**
     * 取得开关状态.
     * 
     * @param x
     *            - 状态
     * @return 开关状态
     */
    private int getSwitchStatus(final int x) {
        return this._switchStatus[x];
    }

    /*
     * 初始设置
     */

    /**
     * 取得陷阱列表(集合内).
     * 
     * @return 陷阱列表(集合内)
     */
    private ArrayList<L1TrapInstance> getTrapList() {
        return this._trapList;
    }

    /**
     * guardman死亡.
     * 
     * @throws InterruptedException
     *             -
     */
    public void guardmanDeath() throws InterruptedException {
        if (this.getSwitchStatus(3) == 0) {
            this.setSwitchStatus(3, 1);
        }
        this.setAlreadyGuardManDeath(true);
        // 先让欧林过去吧！快点去吧！
        this._leader.sendPackets(new S_NPCTalkReturn(this._leader.getId(),
                "j_ep008"));
        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7643", 0)); // 7643 [奥琳]准备好了，先送到[哈丁]那吧。
        if (this.getReceiveAllAction()) {
            Thread.sleep(8000);
            if (this.getActionKerenis() == 1) {
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7567", 0)); // 7567 马上就去。
            } else {
                if (this.getActionKerenis() == 2) {
                    this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                            this._Kerenis, "$7575", 0)); // 7575 [奥！琳！]是没有选择权！
                } else { // 0
                    this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                            this._Kerenis, "$7646", 0)); // 7646 呼...是啊，别在那撒野，叫你去死！
                }
            }
        } else { // 忽略全部
            this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                    "$7644", 0)); // 7644 [奥琳]，无视我吗？
            Thread.sleep(3000);
            if (this.getActionKerenis() == 1) {
                this.setKerenisAngry(true);
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7568", 0)); // yes 7568 [奥！琳！]诅咒你！
            } else {
                // musi 7645 呼...去死！！！
                if (this.getActionKerenis() == 0) {
                    this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                            this._Kerenis, "$7645", 0));
                }
            }
        }
        Thread.sleep(2500);
        L1Teleport.teleport(this._leader, 32718, 32849, this.getMapId(), 5,
                true);
        // killTimer();
        // _Kerenis.deleteMe();
        // _Kerenis=null;
        /*
         * 7647 [奥琳]也到这边了，仪式马上开始，都到这边吧。
         * 7648 所有的门都会马上关掉，都到这边！
         * 7649 没时间了，不能让邪气到地面上！
         */
        this.sendMessage(7647, 0);
        Thread.sleep(4000);
        this.sendMessage(7648, 0);
        Thread.sleep(3000);
        this.sendMessage(7649, 0);
        Thread.sleep(5000);
        if (!this.isDeleteTransactionNow()) {
            this._hq = new HqThread();
            GeneralThreadPool.getInstance().execute(this._hq);
        }

    }

    /**
     * 初始化.
     */
    private void init() {
        this.setActive(true);
        // 1400000 过去的说话之岛 1 91297 32741 32930 0 0 6 0 9000 0
        this._location = new L1Location(32707, 32846, this.getMapId());
        this._switchStatus = new int[4];
        this._roundStatus = new int[12];
        this._randomRuneEffect = new int[5];
        this._doors = new ArrayList<L1DoorInstance>();
        for (int i = 0; i < this._randomRuneEffect.length; i++) {
            this.setRandomRuneEffect(i, -1);
        }
        final RandomGenerator rd = RandomGeneratorFactory.getSharedRandom();
        int value = 0;
        boolean find = false;
        this.setRandomRuneEffect(0, value); // 第二个设置为0
        for (int i = 1; i < 5; i++) {
            while (!find) {
                value = rd.nextInt(4) + 1;
                find = this.serchRandomRuneEffect(value);
            }
            this.setRandomRuneEffect(i, value);
            find = false;
        }
        final L1Location loc = new L1Location();
        loc.set(32742, 32930, this.getMapId());

        this._Kerenis = this.spawnOne(loc, 91297, 6);
        loc.set(32733, 32724, this.getMapId());
        // 魔法阵 91320
        this._Hardin = this.spawnOne(loc, 91330, 6); // 之后瞬移 32716 32846

        // spawnOne(loc,91340,6);
        // 81167 光

        loc.set(32684, 32817, this.getMapId());
        this.spawnOne(loc, 81167, 0); // 森林之光 １道
        loc.set(32732, 32789, this.getMapId());
        this.spawnOne(loc, 81167, 0);
        loc.set(32760, 32791, this.getMapId());
        this.spawnOne(loc, 81167, 0);
        loc.set(32667, 32874, this.getMapId());
        this.spawnOne(loc, 81167, 0);

        loc.set(32729, 32854, this.getMapId());
        this.spawnOne(loc, 81167, 0);
        // 玉
        // 91325 magic-boll 青
        // 91326 magic-boll 赤
        loc.set(32666, 32817, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32668, 32817, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32668, 32819, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32666, 32819, this.getMapId());
        this.spawnOne(loc, 91326, 0);

        loc.set(32809, 32837, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32809, 32839, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32807, 32837, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32807, 32839, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        //
        loc.set(32806, 32863, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32808, 32864, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32800, 32864, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32799, 32866, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32807, 32870, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32806, 32872, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32798, 32872, this.getMapId());
        this.spawnOne(loc, 91339, 0);
        loc.set(32800, 32873, this.getMapId());
        this.spawnOne(loc, 91339, 0);

        loc.set(32802, 32868, this.getMapId());
        this.spawnOne(loc, 91338, 0);

        /* 额外的陷阱 */

        loc.set(32666, 32817, this.getMapId());
        this.setSwitch(loc, 54);
        loc.set(32668, 32817, this.getMapId());
        this.setSwitch(loc, 54);
        loc.set(32668, 32819, this.getMapId());
        this.setSwitch(loc, 54);
        loc.set(32666, 32819, this.getMapId());
        this.setSwitch(loc, 54);

        loc.set(32712, 32793, this.getMapId());
        this.setSwitch(loc, 55);
        loc.set(32703, 32791, this.getMapId());
        this.setSwitch(loc, 55);
        loc.set(32710, 32803, this.getMapId());
        this.setSwitch(loc, 55);
        loc.set(32703, 32800, this.getMapId());
        this.setSwitch(loc, 55);

        loc.set(32807, 32839, this.getMapId());
        this.setSwitch(loc, 56);
        loc.set(32809, 32837, this.getMapId());
        this.setSwitch(loc, 56);
        loc.set(32807, 32837, this.getMapId());
        this.setSwitch(loc, 56);
        loc.set(32809, 32839, this.getMapId());
        this.setSwitch(loc, 56);

        loc.set(32807, 32870, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32806, 32872, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32799, 32866, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32800, 32864, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32808, 32864, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32806, 32863, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32798, 32872, this.getMapId());
        this.setSwitch(loc, 57);
        loc.set(32800, 32873, this.getMapId());
        this.setSwitch(loc, 57);

        loc.set(32684, 32816, this.getMapId());
        this.setSwitch(loc, 60);
        loc.set(32732, 32789, this.getMapId());
        this.setSwitch(loc, 61);
        loc.set(32760, 32791, this.getMapId());
        this.setSwitch(loc, 62);
        loc.set(32729, 32854, this.getMapId());
        this.setSwitch(loc, 63);
        loc.set(32667, 32874, this.getMapId());
        this.setSwitch(loc, 64);

        final int mobGroupIdFirst = 78;
        int mobGroupLeaderId;
        int temp;

        loc.set(32785, 32871, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32725, 32789, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32745, 32813, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32686, 32790, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32664, 32813, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32669, 32850, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32683, 32813, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32715, 32810, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32745, 32789, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32784, 32795, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32805, 32797, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        loc.set(32792, 32828, this.getMapId());
        temp = rd.nextInt(7) + mobGroupIdFirst;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        // loc.set(32748,32847,getMapId());

        loc.set(32775, 32846, this.getMapId());
        temp = 77;
        mobGroupLeaderId = MobGroupTable.getInstance().getTemplate(temp)
                .getLeaderId();
        this.doSpawnGroup(loc, mobGroupLeaderId, temp);
        /* 哈丁的日记：1~10 */
        final int diaryFirstId = 50008;
        final int[] x = { 32763, 32758, 32663, 32667, 32722 };
        final int[] y = { 32800, 32801, 32876, 32867, 32866 };

        for (int i = 0; i < x.length; i++) {
            if (rd.nextInt(100) <= 50) { // 暂定
                loc.set(x[i], y[i], this.getMapId());
                L1World.getInstance().getInventory(loc)
                        .storeItem(diaryFirstId + rd.nextInt(10), 1);
            }
        }
        /* 门 */
        if (this.getMapId() != 9000) {
            for (final L1DoorInstance door : DoorTable.getInstance()
                    .getDoorList()) {
                if (door.getMapId() == 9000) { // 未经指定的GFXID
                    // addDoor(door,door.getGfxId());
                }
            }
        }
        this.createWalls();
        // 91316 red
        // 91317　red魔法阵　闪烁
        // 91318 白
        // 91319　白魔法阵　闪烁
    }

    /**
     * 能否入场～任务结束.
     * 
     * @return true:可以、false:不能
     */
    public boolean isActive() {
        return this._active;
    }

    /**
     * 是否已有的第一个开关.
     * 
     * @return true:是、false:否
     */
    public boolean isAlreadyFirstSwitch() {
        return this._alreadyFirstSwitch;
    }

    /**
     * 死亡者是否为已有的队员.
     * 
     * @return true:是、false:否
     */
    private boolean isAlreadyGuardManDeath() {
        return this._alreadyGuardManDeath;
    }

    /**
     * 是否为已有的入口.
     * 
     * @return true:是、false:否
     */
    public boolean isAlreadyPortal() {
        return this._alreadyPortal;
    }

    /**
     * 是否已有的第二个开关.
     * 
     * @return true:是、false:否
     */
    public boolean isAlreadySecondSwitch() {
        return this._alreadySecondSwitch;
    }

    /**
     * 是否创造黑色符文.
     * 
     * @return true:是、false:否
     */
    private boolean isBlackRuneCreated() {
        return this._blackRune;
    }

    /**
     * 是否为踩踏出的已有符文.
     * 
     * @return true:是、false:否
     */
    private boolean isBlackRuneTrodAlready() {
        return this._BlackRuneTrodAlready;
    }

    /**
     * 是否为奖励阶段.
     * 
     * @return true:是、false:否
     */
    private boolean isBonusStage() {
        return this._bonusStage;
    }

    /**
     * 是否立即删除事物.
     * 
     * @return true:是、false:否
     */
    public boolean isDeleteTransactionNow() {
        return this._deleteTransactionNow;
    }

    /**
     * 是否为困难模式.
     * 
     * @return true:是、false:否
     */
    private boolean isHardMode() {
        boolean flag = true;
        for (int n = 0; n < this._switchStatus.length - 1; n++) {
            if (this.getSwitchStatus(n) != 1) { // 1=快
                flag = false;
                break;
            }
        }
        return flag;
    }

    /**
     * 是否为愤怒的凯尔尼斯.
     * 
     * @return true:是、false:否
     */
    private boolean isKerenisAngry() {
        return this._kerenisAngry;
    }

    /**
     * 结束计时器.
     */
    private void killTimer() {
        try {

            /* 凯尔尼斯　随机说话　计时器 */
            if (this._krm != null) {
                this._krm.cancel();
                this._krm = null;
            }
            /* 凯尔尼斯　随机攻击　计时器 */
            if (this._ak != null) {
                this._ak.cancel();
                this._ak = null;
            }
            /* 妖魔 召唤袭击者 计时器 */
            if (this._as != null) {
                this._as.cancel();
                this._as = null;
            }
            /* 凯尔尼斯 出现巴风特 */
            if (this._sb != null) {
                this._sb.cancel();
                this._sb = null;
            }
            /* 任务启动消息 */
            if (this._preliminary != null) {
                this._preliminary.join();
                this._preliminary = null;
            }
            /* 黑墙移动 */
            if (this._mw != null) {
                this._mw.cancel();
                this._mw = null;
            }
            /*
             * 监视器 if (_hqm != null) { _hqm.cancel(); _hqm = null; }
             */

            /* 妖魔出现计时器 */
            if (this._ov != null) {
                this._ov.cancel();
                this._ov = null;
            }

            /* UB(仪式)线程 */
            if (this._hq != null) {
                this._hq.join(); // 等到最后
                this._hq = null;
            }

            /* 凯尔尼斯 Start 进展1~4部分 */
            if (this._kp1 != null) {
                this._kp1.join(); // 等到最后
                this._kp1 = null;
            }
            if (this._kp2 != null) {
                this._kp2.join(); // 等到最后
                this._kp2 = null;
            }
            if (this._kp3 != null) {
                this._kp3.join(); // 等到最后
                this._kp3 = null;
            }
            if (this._kp4 != null) {
                this._kp4.join(); // 等到最后
                this._kp4 = null;
            }
            /* 炎魔出现(友情客串) */
            if (this._gs != null) {
                this._gs.join(); // 等到最后
                this._gs = null;
            }
            /* 凯尔尼斯 进展 第一部分　End */
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * @param npc
     * @throws InterruptedException
     */
    public void lunkerDie(final L1NpcInstance npc) throws InterruptedException {
        boolean kerenisSpawn = false;
        boolean guestSpawn = false;
        if (!this.isKerenisAngry()) {
            kerenisSpawn = true; // 小凯尔尼斯
        } else {
            if (this.isHardMode()) { // 黑翼凯尔尼斯
                kerenisSpawn = true;
            }
        }
        if (this.isHardMode()) {
            guestSpawn = true;
        }

        if (kerenisSpawn) {
            // 凯尔尼斯
            if ((npc.getNpcId() == 91295) || (npc.getNpcId() == 91296)) {
                boolean find = false;
                for (final L1Object obj : L1World.getInstance()
                        .getVisiblePoint(this.getLocation(), 15)) {
                    if (obj instanceof L1MonsterInstance) {
                        if ((((L1MonsterInstance) obj).getNpcId() == 91295)
                                || (((L1MonsterInstance) obj).getNpcId() == 91296)) {
                            if (!((L1MonsterInstance) obj).isDead()) {
                                find = true;
                            }
                            break;
                        }
                    }
                }
                if (find) { // 没有死

                } else { // 预先死亡
                    if (guestSpawn) {
                        this._gs = new GuestSpawn();
                        GeneralThreadPool.getInstance().execute(this._gs);
                        this._mw = new MoveWall();
                        this._mw.begin();
                    }
                }
            } else { // バフォ　死神
                boolean find = false;
                for (final L1Object obj : L1World.getInstance()
                        .getVisiblePoint(this.getLocation(), 15)) {
                    if (obj instanceof L1MonsterInstance) {
                        if ((((L1MonsterInstance) obj).getNpcId() == 91295)
                                || (((L1MonsterInstance) obj).getNpcId() == 91296)) {
                            if (!((L1MonsterInstance) obj).isDead()) {
                                find = true;
                            }
                            break;
                        }
                    }
                }
                if (find) { // 没有死

                } else { // 预先死亡
                    if (guestSpawn) {
                        this._gs = new GuestSpawn();
                        GeneralThreadPool.getInstance().execute(this._gs);
                        this._mw = new MoveWall();
                        this._mw.begin();
                    }
                }
            }
        } else { // 1只的情况没有必要搜索
            if (guestSpawn) {
                this._gs = new GuestSpawn();
                GeneralThreadPool.getInstance().execute(this._gs);
                this._mw = new MoveWall();
                this._mw.begin();
            }
        }
    }

    /**
     * 移动黑墙.
     */
    public void moveWall() {
        new MoveWall().begin();
    }

    /**
     * 黑色符文.
     * 
     * @throws InterruptedException
     *             -
     */
    public void onBlackRune() throws InterruptedException {
        // 魔法阵 32802 32868
        // 上
        // 左
        // →
        // 下
        /*
         * 中间的房有4个通路，最后一个房也有4个通路。
         * 中间的房周围是墙壁，最后一个房周围是草地。
         * 草地是每2个组成一起，而且是性格相似。
         * 将要听到的是对草地的一些帮助。
         * getRandomRuneEffect(type-1)*2+((type+getRandomRuneEffect(type))%2)
         * 8681 [近战攻击力]
         * 8682 [近战命中率]
         * 8685 [魔攻]
         * 8686 [咒文命中率]
         * 8683 [远距离攻击力]
         * 8684 [远距离命中率]
         * 8687 [昏迷耐性]
         * 8688 [支撑耐性]
         */
        if (this.isBlackRuneTrodAlready()) {
            return;
        }
        this.setBlackRuneTrodAlready(true);
        final int[] itemlist = { 40002, 40003, 40002, 40003, 40002, 40003,
                40002, 40003 };
        final int mapId = this.getMapId();
        int cnt = 0;
        int starCount = 0; // 选项。星を付加する　未实装
        for (int i = 0; i < this.getOnPlayerList().length; i++) {
            if (this.getOnPlayerList()[i] != 0) {
                starCount++;
            }
        }
        final L1Location loc = new L1Location(32802, 32868, mapId); // 黑色符文
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                for (int i = 0; i < this.getOnPlayerList().length; i++) {
                    if (obj.getId() == this.getOnPlayerList()[i]) {
                        final int effectNum = (int) Math.floor((double) i / 2) + 1;
                        int item;
                        final int flag = (effectNum + this
                                .getRandomRuneEffect(effectNum)) % 2;
                        if (flag == 1) { // 奇数
                            item = itemlist[this
                                    .getRandomRuneEffect((effectNum) - 1)
                                    * 2
                                    + ((effectNum + this
                                            .getRandomRuneEffect(effectNum)) % 2)];
                        } else { // 偶数
                            item = itemlist[this
                                    .getRandomRuneEffect((effectNum) - 1) * 2];
                        }
                        L1World.getInstance().getInventory(loc)
                                .storeItem(item, 1);
                    }
                }
            }
        }
        loc.set(32806, 32863, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        loc.set(32808, 32864, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }

            }
        }

        cnt++;
        loc.set(32800, 32864, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        loc.set(32799, 32866, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        cnt++;
        loc.set(32807, 32870, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        loc.set(32806, 32872, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        cnt++;
        loc.set(32798, 32872, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        loc.set(32800, 32873, mapId);
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(loc, 0)) {
            if (obj instanceof L1PcInstance) {
                if (obj.getId() == this.getOnPlayerList()[cnt]) {
                    final int effectNum = (int) Math.floor((double) cnt / 2) + 1;
                    int item;
                    final int flag = (effectNum + this
                            .getRandomRuneEffect(effectNum)) % 2;
                    if (flag == 1) { // 奇数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1)
                                * 2
                                + ((effectNum + this
                                        .getRandomRuneEffect(effectNum)) % 2)];
                    } else { // 偶数
                        item = itemlist[this
                                .getRandomRuneEffect((effectNum) - 1) * 2];
                    }
                    L1World.getInstance().getInventory(loc).storeItem(item, 1);
                }
            }
        }

        /*
         * 8719 因为启动了中间脚板,决定了补偿.
         */
        Thread.sleep(30 * 1000); // 30秒后强制传回
        if (!this.isDeleteTransactionNow()) {
            this.outPushPlayer(); // end();
        }
    }

    /**
     * 第一个开关.
     * 
     * @throws InterruptedException
     *             -
     */
    public void onFirstSwitch() throws InterruptedException { // 32741 32930
        if (!this.isDeleteTransactionNow()) {
            this._kp2 = new KerenisPart2();
            GeneralThreadPool.getInstance().execute(this._kp2);
        }

        if (this.getSwitchStatus(0) == 0) {
            this.setSwitchStatus(0, 1);
        }
        this.setAlreadyFirstSwitch(true);
        /* グラフィックを表示させる */
        final L1Location loc = new L1Location(32744, 32932, this.getMapId());
        this.spawnOne(loc, 91326, 0); // 赤玉
        loc.set(32667, 32818, this.getMapId());
        this.spawnOne(loc, 91318, 0); // 魔法阵-白

        this._Hardin.broadcastPacket(new S_NpcChatPacket(this._Hardin, "$7621",
                0)); // 7621 赶紧设置弓箭陷阱到这边帮忙。对你们是简单的事情。
        // 妖魔计时器
        /* 计时器启动 */
        this._ov = new OrcVocabulary();
        this._ov.begin();

        // 啊！那些妖魔...这麻烦了，欧林拜托你了。
        this._leader.sendPackets(new S_NPCTalkReturn(this._leader.getId(),
                "j_ep005"));
        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7623", 0)); // 7623 哎呀！[妖魔]嘛！以前弄成白色的妖魔也来了！[奥琳]拜托了！
        Thread.sleep(8000);
        if (this.getActionKerenis() == 1) {
            this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                    "$7564", 0)); // 7564 是啊，因为是[奥琳]，至少会引起注意的。
        } else {
            if (this.getActionKerenis() == 2) {
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7572", 0)); // 7572 [奥！琳！]这是你的职责！
            } else { // 0
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7624", 0)); // 7624 [奥琳]吓到了？！
            }
        }

        // 妖魔出现
        final int mobGroupLeaderId = MobGroupTable.getInstance()
                .getTemplate(85).getLeaderId();
        this.doSpawnGroup(this._leader.getLocation(), mobGroupLeaderId, 85);
        // 设置定时器
        // 导致随机MobGroup的出现
        this._as = new AssailantSpawn();
        this._as.begin();
        this._ak = new AttackKerenis();
        this._ak.begin();
        // 如果你有做接近敌人的魔法攻击。随机N秒后等待
    }

    /**
     * 第二个开关.
     * 
     * @throws InterruptedException
     *             -
     */
    public void onSecondSwitch() throws InterruptedException {
        if (!this.isDeleteTransactionNow()) {
            this._kp3 = new KerenisPart3();
            GeneralThreadPool.getInstance().execute(this._kp3);
        }
        if (this.getSwitchStatus(1) == 0) {
            this.setSwitchStatus(1, 1);
        }
        this.setAlreadySecondSwitch(true);
        final L1Location loc = new L1Location(32740, 32928, this.getMapId());
        this.spawnOne(loc, 91326, 0);
        loc.set(32712, 32793, this.getMapId());
        this.spawnOne(loc, 81167, 0); // 森林之光 １道
        loc.set(32703, 32791, this.getMapId());
        this.spawnOne(loc, 81167, 0);
        loc.set(32710, 32803, this.getMapId());
        this.spawnOne(loc, 81167, 0);
        loc.set(32703, 32800, this.getMapId());
        this.spawnOne(loc, 81167, 0);

        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7629", 0)); // 7629 啊啊...虽然还能忍耐但最好再快点...
        this._Hardin.broadcastPacket(new S_NpcChatPacket(this._Hardin, "$7628",
                0)); // 7628 辛苦了！希望再快点。这次更简单，设置往这边过来的魔法阵吧！
        // 妖魔怎么处理！海拉知不知道这里是妖魔的巢穴呢？
        this._leader.sendPackets(new S_NPCTalkReturn(this._leader.getId(),
                "j_ep006"));
        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7630", 0)); // 7630 [哈丁]分明知道这里是妖魔的巢穴吧！
        Thread.sleep(8000);
        final int mobGroupLeaderId = MobGroupTable.getInstance()
                .getTemplate(85).getLeaderId();
        this.doSpawnGroup(this._leader.getLocation(), mobGroupLeaderId, 85);
        if (this.getActionKerenis() == 1) {
            this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                    "$7565", 0)); // 7565 该死的老头！
        } else {
            if (this.getActionKerenis() == 2) {
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7573", 0)); // 7573 不是在这生活很久了嘛！不可信！
            } else { // 0
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7631", 0)); // 7631 [奥琳]别打嗝！你这傻瓜！
            }
        }
    }

    /**
     * 第三个开关.
     * 
     * @throws InterruptedException
     *             -
     */
    public void onThirdSwitch() throws InterruptedException {
        if (!this.isDeleteTransactionNow()) {
            this._kp4 = new KerenisPart4();
            GeneralThreadPool.getInstance().execute(this._kp4);
        }

        if (this.getSwitchStatus(2) == 0) {
            this.setSwitchStatus(2, 1);
        }
        this.setAlreadyPortal(true);
        final L1Location loc = new L1Location(32743, 32929, this.getMapId());
        this.spawnOne(loc, 91326, 0);

        /* 将显示瞬移之前的图形 */
        loc.set(32787, 32821, this.getMapId());
        this.spawnOne(loc, 91318, 0); // 魔法阵-白
        /* 瞬移入口的图形 */
        loc.set(32808, 32838, this.getMapId());
        this.spawnOne(loc, 91319, 0); // 魔法阵-白(闪烁)
        /* 在世界上创建添加新的陷阱 */
        this.setSwitch(loc, 53);

        this._Hardin.broadcastPacket(new S_NpcChatPacket(this._Hardin, "$7635",
                0)); // 7635 好！处理完门卫后到这边吧。
        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7536", 0)); // 7636 唔...精神力下降...啊...啊...
        // 只剩最后一个了。欧林加油！
        this._leader.sendPackets(new S_NPCTalkReturn(this._leader.getId(),
                "j_ep007"));
        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7637", 0)); // 7637 就剩最后一个了。[奥琳]加油！
        Thread.sleep(8000);
        if (this.getActionKerenis() == 1) {
            this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                    "$7566", 0)); // 7566 好吧好吧
        } else {
            if (this.getActionKerenis() == 2) {
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7574", 0)); // 7574 [奥！琳！]你这傻瓜！
            } else { // 0
                this._Kerenis.broadcastPacket(new S_NpcChatPacket(
                        this._Kerenis, "$7638", 0)); // 7638 [奥琳！！！]
            }
        }
        // 敌人出现
        this._Kerenis.broadcastPacket(new S_NpcChatPacket(this._Kerenis,
                "$7639", 0)); // 7639 这是什么！！！
    }

    /**
     * 驱逐在MAP中的所有队员.
     */
    private void outPushPlayer() {
        // 将同个地监内的PC驱逐(传送)出来
        for (final L1PcInstance pc : L1World.getInstance().getAllPlayers()) {
            if (pc.getMapId() == this.getMapId()) {
                final RandomGenerator random = RandomGeneratorFactory
                        .getSharedRandom();
                final int rndx = random.nextInt(4);
                final int rndy = random.nextInt(4);
                final int locx = 32587 + rndx;
                final int locy = 32941 + rndy;
                final short mapid = 0;
                L1Teleport.teleport(pc, locx, locy, mapid, 5, true);
            }
        }
    }

    /**
     * 删除门.
     * 
     * @param door
     *            - 门
     */
    private void removeDoor(final L1DoorInstance door) {
        this.getAllDoors().remove(door);
        DoorTable.getInstance().deleteDoorByLocation(door.getLocation());
    }

    /**
     * 重置.
     */
    private void reset() {
        try {

            for (final L1Object obj : L1World.getInstance().getObject()) {
                if (obj.getMapId() == this.getMapId()) {
                    if (obj instanceof L1FieldObjectInstance) {
                        L1World.getInstance().removeVisibleObject(obj);
                        L1World.getInstance().removeObject(obj);
                    } else if (obj instanceof L1EffectInstance) {
                        L1World.getInstance().removeVisibleObject(obj);
                        L1World.getInstance().removeObject(obj);
                    } else if (obj instanceof L1ItemInstance) {
                        final L1Inventory groundInventory = L1World
                                .getInstance().getInventory(obj.getX(),
                                        obj.getY(), obj.getMapId());
                        groundInventory.deleteItem((L1ItemInstance) obj);
                        L1World.getInstance().removeVisibleObject(obj);
                        L1World.getInstance().removeObject(obj);
                    } else if (obj instanceof L1DoorInstance) {
                        if (obj.getMapId() == 9000) {
                            if ((((L1DoorInstance) obj).getGfxId() >= 7534)
                                    && (((L1DoorInstance) obj).getGfxId() <= 7537)) { // 移动黑墙除外
                                this.removeDoor((L1DoorInstance) obj);
                            } else {
                                ((L1DoorInstance) obj).close();
                            }
                        } else {
                            this.removeDoor((L1DoorInstance) obj);
                        }
                    } else if (obj instanceof L1NpcInstance) {
                        ((L1NpcInstance) obj).deleteMe();
                    }
                }
            }
            for (final L1TrapInstance obj : this.getTrapList()) {
                if (obj.getMapId() == this.getMapId()) {
                    // System.out.println("通过");
                    L1WorldTraps.getInstance().removeTrap(obj);
                }
            }
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 选择召唤.
     * 
     * @param pattern
     *            - 模式
     * @param curRound
     *            - 当前回合
     * @throws InterruptedException
     *             -
     */
    private void selectSpawn(final int pattern, final int curRound)
            throws InterruptedException {
        final int[] npcid = { 91274, 91275, 91276, 91277, 91278, 91279, 91280,
                91281, 91282, 91283, 91284, 91285, 91286, 91287, 91288, 91289,
                91292 };
        /*
         * int lv[]={ 27 ,// 魔界の スケルトン ガード 27 ,// 魔界の スケルトン マークスマン 29 ,// 魔界の
         * スケルトン ファイター 30 ,// 魔界の ダーク エレメンタル 32 ,// 魔界の サラマンダー 33 ,// 魔界の ゲイザー
         * 37 ,// 魔界の サキュバス 42 ,// 魔界の オーク ゾンビ 44 ,// 魔界の ライカンスロープ 44 ,// 魔界の
         * レッサー デーモン
         * 
         * 46 ,// 魔界の ホーン ケルベロス 46 ,// 魔界の イフリート
         * 
         * 47 ,// 魔界の ボーンドラゴン 48 ,// 魔界の バーニング アーチャー 50 ,// 魔界の バーニング ウォリアー 54
         * ,// 魔界の シアー 55 ,// 魔界の グレート ミノタウルス
         * 
         * };
         */
        final RandomGenerator random = RandomGeneratorFactory.getSharedRandom();
        int startPoint = 0;
        int endPoint = 16;
        int delay = 0;
        final int[] X = { 32706, 32695, 32702, 32717, 32706 };
        final int[] Y = { 32836, 32847, 32855, 32847, 32846 };
        final L1Location loc = new L1Location();
        if (pattern != 1) {
            // if(pattern==3){
            // startPoint=12;
            // }else{
            startPoint = 9;
            endPoint = 14;
            // }
        } else {
            endPoint = 6;
        }
        for (int i = 0; i < curRound - 1; i++) {
            if (this.getRoundStatus(i) == 1) {
                if (endPoint < 16) {
                    startPoint++;
                    endPoint++;
                } else {
                    break;
                }
            }
        }
        for (int i = 0; startPoint + i <= endPoint; i++) {
            final int n = random.nextInt(5);
            loc.set(X[n] - 3 + random.nextInt(6), Y[n] - 3 + random.nextInt(6),
                    this.getMapId());
            if (this.isBonusStage()) {
                final int s = random.nextInt(4);
                for (final L1PcInstance pc : L1World.getInstance()
                        .getAllPlayers()) {
                    if (pc.getMapId() == this.getMapId()) {
                        pc.sendPackets(new S_SkillSound(pc.getId(), 2028 + s));
                        pc.broadcastPacket(new S_SkillSound(pc.getId(),
                                2028 + s));
                    }
                }
                // 神秘的显示和抖动 WAHT THE!!
                this.spawnOneMob(loc, 91337); // 葛林:奖金怪物捣蛋鬼(秘谭)
            } else {
                this.spawnOneMob(
                        loc,
                        npcid[startPoint
                                + random.nextInt(endPoint - startPoint)]);
            }
            delay += 500;
            Thread.sleep(500);
        }
        Thread.sleep(9000 - delay);
    }

    /**
     * 发送BOSS的回合信息.
     * 
     * @param curRound
     *            - 当前回合
     * @throws InterruptedException
     *             -
     */
    private void sendBossRoundMessage(final int curRound)
            throws InterruptedException {
        /*
         * 8704 第四个封印解除了[4/12]
         * 8705 谁叫醒我了…我…累啊…
         * 8706 第八个封印解除了[8/12]
         * 8707 门开了么!
         */
        if (curRound / 4 > 1) {
            this.sendMessage(8706, 0); // blue
            Thread.sleep(2000);
            this.sendMessage(8707, 0); // blue
        } else {
            this.sendMessage(8704, 0); // blue
            Thread.sleep(2000);
            this.sendMessage(8705, 0); // blue
        }
        this._sb = new SpawnBoss();
        this._sb.begin();

    }

    /**
     * UB开始时发送倒计时.
     * 
     * @throws InterruptedException
     *             -
     */
    private void sendCountDown() throws InterruptedException {
        /*
         * 7650 邪恶的怪物们会利用次元警戒的漏洞聚集的！
         * 7651 都准备一下！
         */
        Thread.sleep(4000);
        this.sendMessage(7650, 0);
        Thread.sleep(4000);
        this.sendMessage(7651, 0);
        Thread.sleep(4000);
    }

    /**
     * 给参加的队员发送信息(S_ServerMessage).
     * 画面正中的蓝色消息
     * 
     * @param nameId
     *            发送的nameId
     * @param cases
     *            [未使用]发送的范围:0=ALL、1=队长、2=MAP内除本人外的所有队员
     */
    private void sendMessage(final int nameId, final int cases) {
        for (final L1PcInstance pc : L1World.getInstance().getAllPlayers()) {
            if (pc.getMapId() == this.getMapId()) {
                pc.sendPackets(new S_BlueMessage(166, "$" + nameId));
            }
        }
    }

    /**
     * 在每次回合开始时发送信息.
     * 
     * @param curRound
     *            - 当前回合
     * 
     * @throws InterruptedException
     *             -
     */
    private void sendRoundMessage(final int curRound)
            throws InterruptedException {
        /*
         * 8708 第一个封印解除了[1/12]
         * 8709 第二个封印解除了[2/12]
         * 8710 第三个封印解除了[3/12]
         * 8711 第五个封印解除了[5/12]
         * 8712 第六个封印解除了[6/12]
         * 8713 第七个封印解除了[7/12]
         * 8714 第九个封印解除了[9/12]
         * 8715 第十个封印解除了[10/12]
         * 8716 第十一个封印解除了[11/12]
         */
        final int MSGID = 8708; // 第一个封印解除了[1/12]
        if ((curRound % 4 == 0) && (curRound != 12)) {
            Thread.sleep(5000);
            this.sendBossRoundMessage(curRound);
        } else {
            if (curRound != 12) {
                Thread.sleep(7000);
                this.sendMessage(
                        MSGID + curRound
                                - (int) (1 + Math.floor(curRound / 4D)), 0);
                Thread.sleep(2000);
            } else {
                this.sendMessage(7654, 0); // 大家都振作点！巨大的黑暗要来临！
                Thread.sleep(15000);
                // 8717 最后一个封印解除了[12/12]
                this.sendMessage(8714, 0); // 第九个封印解除了[9/12]
                Thread.sleep(2000);
                this._sb = new SpawnBoss();
                this._sb.begin();
            }
        }
    }

    /**
     * 在次轮开始发送消息.
     * 
     * @param curSubRound
     *            当前次轮
     */
    private void sendSubRoundMessage(final int curSubRound) {
        /*
         * 8689 封印解开了点[1/4]
         * 8690 封印揭开了一半[2/4]
         * 8691 封印解开了一半以上[3/4]
         * 8692 封印完全解开了[4/4]
         */
        final int msgId = 8689; // 封印解开了点[1/4]
        this.sendMessage(msgId + curSubRound - 1, 0);
    }

    /**
     * 给地图内的全员发送信息 8720 悄悄话传到了奥琳的耳朵里.
     * 
     * 如果角色为队长则显示HTML
     * 
     * @param type
     *            踩到的类型:0=说明、1=北、2=西、3=东、4=南
     */
    public void sendWisperWindow(final int type) {
        // if(_leader.isInParty()){
        // for(L1PcInstance pc:_leader.getParty().getMembers()){
        // pc.sendPackets(new S_ServerMessage(8720));
        if (this.getMapId() == this._leader.getMapId()) {
            this._leader.sendPackets(new S_ServerMessage(8720));
            // 8720 悄悄话传到了奥琳的耳朵里.
        }
        // }
        // }

        /*
         * 中间的房有4个通路，最后一个房也有4个通路。
         * 中间的房周围是墙壁，最后一个房周围是草地。
         * 草地是每2个组成一起，而且是性格相似。
         * 将要听到的是对草地的一些帮助。
         * getRandomRuneEffect(type-1)*2+((type+getRandomRuneEffect(type))%2)
         * 8681 [近战攻击力]
         * 8682 [近战命中率]
         * 8685 [魔攻]
         * 8686 [咒文命中率]
         * 8683 [远距离攻击力]
         * 8684 [远距离命中率]
         * 8687 [昏迷耐性]
         * 8688 [支撑耐性]
         */
        if (this.getMapId() == this._leader.getMapId()) {
            if (type == 0) {
                this._leader.sendPackets(new S_NPCTalkReturn(this._leader
                        .getId(), "j_int00")); // 说明
            } else {
                final String[] EffectBase = { "$8681", "$8682", "$8685",
                        "$8686", "$8683", "$8684", "$8687", "$8688" };
                final String[] EffectType = { EffectBase[(this
                        .getRandomRuneEffect(type) - 1)
                        * 2
                        + ((type + this.getRandomRuneEffect(type)) % 2)] };
                if (type == 1) {
                    this._leader.sendPackets(new S_NPCTalkReturn(this._leader
                            .getId(), "j_int01", EffectType)); // 北
                } else if (type == 2) {
                    this._leader.sendPackets(new S_NPCTalkReturn(this._leader
                            .getId(), "j_int02", EffectType)); // 西
                } else if (type == 3) {
                    this._leader.sendPackets(new S_NPCTalkReturn(this._leader
                            .getId(), "j_int03", EffectType)); // 东
                } else if (type == 4) {
                    this._leader.sendPackets(new S_NPCTalkReturn(this._leader
                            .getId(), "j_int04", EffectType)); // 南
                }
            }
        }
    }

    /**
     * 搜索怪物数量.
     * 
     * @return 怪物数量
     */
    private int serchCountMonster() {
        int mobCnt = 0;
        for (final L1Object obj : L1World.getInstance().getVisiblePoint(
                this.getLocation(), 13)) {
            if (obj instanceof L1MonsterInstance) {
                if (!((L1MonsterInstance) obj).isDead()) {
                    mobCnt++;
                }
            }
        }
        return mobCnt;
    }

    /**
     * 检查value中是否有重复的值.
     * 
     * @param value
     *            - 检查值
     * @return true=不重复、false=重复
     */
    private boolean serchRandomRuneEffect(final int value) {
        boolean result = true;
        for (int i = 0; i < 5; i++) {
            if (value == this.getRandomRuneEffect(i)) {
                result = false;
                break;
            }
        }
        return result;
    }

    /**
     * 设置哈丁的应答动作.
     * 
     * @param actionCode
     *            - 动作代码
     */
    public void setActionHardin(int actionCode) {
        if (actionCode == ActionCodes.ACTION_THINK) { // Alt+4
            actionCode = 2; // 否定
        } else {
            if (actionCode == ActionCodes.ACTION_CHEER) { // Alt+2
                actionCode = 1; // 肯定
            } else {
                return; // 其他无视
            }
        }
        this._actionHardin = actionCode;
    }

    /**
     * 设置凯尔尼斯的应答动作.
     * 
     * @param actionCode
     *            - 动作代码
     */
    public void setActionKerenis(int actionCode) {
        if (actionCode == ActionCodes.ACTION_THINK) { // Alt+4
            actionCode = 2; // 否定
        } else {
            if (actionCode == ActionCodes.ACTION_CHEER) { // Alt+2
                actionCode = 1; // 肯定
            } else {
                return; // 其他无视
            }
        }
        this.setReceiveAllAction(this.getReceiveAllAction() | true);
        this._actionKerenis = actionCode;
    }

    /**
     * 设置实例状态.
     * 
     * @param active
     *            true=Active false=Non-Active
     */
    private void setActive(final boolean active) {
        this._active = active;
    }

    /**
     * 设置已有的第一个开关.
     * 
     * @param firstSwitch
     *            - 总是指定 True
     */
    private void setAlreadyFirstSwitch(final boolean firstSwitch) {
        this._alreadyFirstSwitch = firstSwitch;
    }

    /**
     * 设置已有的队员死亡者.
     * 
     * @param guradManDeath
     *            - 总是指定 True
     */
    private void setAlreadyGuardManDeath(final boolean guradManDeath) {
        this._alreadyGuardManDeath = guradManDeath;
    }

    /**
     * 设置已有的入口.
     * 
     * @param flag
     *            - 总是指定 True
     */
    private void setAlreadyPortal(final boolean flag) {
        this._alreadyPortal = flag;
    }

    /**
     * 设置已有的第二个开关.
     * 
     * @param secondSwitch
     *            -
     */
    private void setAlreadySecondSwitch(final boolean secondSwitch) {
        this._alreadySecondSwitch = secondSwitch;
    }

    /**
     * 设置要显示的黑色魔法阵、要更新的队员名单。 ※玩家名单踩踏可以改变.
     * 
     * @param onPlayerList
     *            - 玩家名单列表
     */
    public void setBlackRune(final int[] onPlayerList) {
        this.setOnPlayerList(onPlayerList);
        /* 显示的黑色符文图形 */
        if (!this.isBlackRuneCreated()) {
            final L1Location loc = new L1Location();
            loc.set(32802, 32868, this._mapId);
            this.spawnOne(loc, 91338, 0); // 黑色符文-小
            this.setSwitch(loc, 59);
            this._blackRune = true;
        }
    }

    /**
     * 设置当踏上黑魔法阵要执行的.
     * 
     * @param trod
     *            -总是指定 True
     */
    private void setBlackRuneTrodAlready(final boolean trod) {
        this._BlackRuneTrodAlready = trod;
    }

    /**
     * 设置奖励阶段.
     * 
     * @param flag
     *            - true or false
     */
    private void setBonusStage(final boolean flag) {
        this._bonusStage = flag;
    }

    /**
     * 更新本回合.
     * 
     * @param curRound
     *            - 本轮
     */
    private void setCurRound(final int curRound) {
        this._curRound = curRound;
    }

    /**
     * 设置立即删除事物.
     * 
     * @param transactionNow
     *            - 当前的事物
     */
    private void setDeleteTransactionNow(final boolean transactionNow) {
        this._deleteTransactionNow = transactionNow;

    }

    /**
     * 当凯尔尼斯被激怒的时候调用.
     * 
     * @param angry
     *            - 总是指定 True
     */
    private void setKerenisAngry(final boolean angry) {
        this._kerenisAngry = angry;
    }

    /**
     * 设置队长.
     * 
     * @param leader
     *            - 对象
     */
    public void setLeader(final L1PcInstance leader) {
        this._leader = leader;
    }

    /**
     * 设置地图ID.
     * 
     * @param mapId
     *            - 地图ID
     */
    private void setMapId(final short mapId) {
        this._mapId = mapId;
    }

    /**
     * 设置要储存的玩家名单列表.
     * 
     * @param onPlayerList
     *            - 玩家名单列表
     */
    private void setOnPlayerList(final int[] onPlayerList) {
        this._onPlayerList = onPlayerList;
    }

    /**
     * 设置随机符文效果.
     * 
     * @param i
     *            - 0=说明　1=北　2=西　3=东　4=南
     * @param value
     *            - 任意值
     */
    private void setRandomRuneEffect(final int i, final int value) {
        this._randomRuneEffect[i] = value;
    }

    /**
     * 设置接收的所有动作(响应凯尔尼斯的问题).
     * 
     * @param action
     *            - 总是指定 True
     */
    private void setReceiveAllAction(final boolean action) {
        this._receiveAllAction = action;
    }

    /**
     * 设置保存每一轮的进展状况.
     * 
     * @param round
     *            - 任何一轮
     * @param value
     *            - 0=迟、1=早
     */
    private void setRoundStatus(final int round, final int value) {
        this._roundStatus[round] = value;
    }

    /**
     * 请注意，它被用作删除和执行创建和添加新的陷阱※L1ReloadTrap.
     * 
     * @param loc
     *            - 任意的坐标位置
     * @param id
     *            - 陷阱ID
     */
    private void setSwitch(final L1Location loc, final int id) {
        final int trapId = id;
        final L1Trap trapTemp = TrapTable.getInstance().getTemplate(trapId);
        final Point rndPt = new Point();
        rndPt.setX(0);
        rndPt.setY(0);
        final int span = 0;
        final L1TrapInstance trap = new L1TrapInstance(IdFactory.getInstance()
                .nextId(), trapTemp, loc, rndPt, span);
        L1World.getInstance().addVisibleObject(trap);

        L1WorldTraps.getInstance().addTrap(trap);

        this.addTrapList(trap);
    }

    /**
     * 设置SwitchStatus数组的第二元素的开关状态.
     * 
     * @param x
     *            - 指数
     * @param status
     *            - 状态:1=快 2=慢 0=太慢或根本没有踩到
     */
    private void setSwitchStatus(final int x, final int status) {
        this._switchStatus[x] = status;
    }

    /**
     * 在指定的位置产生任意的一个NPC.
     * 
     * @param loc
     *            - 出现位置
     * @param npcid
     *            - 任意的NpcId
     * @param heading
     *            - 面向
     * @return L1NpcInstance 返回值: 成功=生成实例 失败=null
     */
    private L1NpcInstance spawnOne(final L1Location loc, final int npcid,
            final int heading) {
        final L1NpcInstance mob = new L1NpcInstance(NpcTable.getInstance()
                .getTemplate(npcid));
        mob.setId(IdFactory.getInstance().nextId());
        mob.setHeading(heading);
        mob.setX(loc.getX());
        mob.setHomeX(loc.getX());
        mob.setY(loc.getY());
        mob.setHomeY(loc.getY());
        mob.setMap(loc.getMapId());

        L1World.getInstance().storeObject(mob);
        L1World.getInstance().addVisibleObject(mob);

        final S_NPCPack npcPack = new S_NPCPack(mob);
        for (final L1PcInstance pc : L1World.getInstance().getRecognizePlayer(
                mob)) {
            pc.addKnownObject(mob);
            mob.addKnownObject(pc);
            pc.sendPackets(npcPack);
        }
        // 怪物ＡＩ开始
        mob.onNpcAI();
        mob.updateLight();
        mob.startChat(L1NpcInstance.CHAT_TIMING_APPEARANCE); // 开始喊话
        return mob;
    }

    /**
     * 在指定的位置产生一个任意的怪物.
     * 
     * @param loc
     *            - 出现位置
     * @param npcid
     *            - 任意的NpcId
     * @return L1MonsterInstance 返回值: 成功=生成实例 失败=null
     */
    private L1MonsterInstance spawnOneMob(final L1Location loc, final int npcid) {
        final L1MonsterInstance mob = new L1MonsterInstance(NpcTable
                .getInstance().getTemplate(npcid));
        mob.setId(IdFactory.getInstance().nextId());
        mob.setHeading(5);
        mob.setX(loc.getX());
        mob.setHomeX(loc.getX());
        mob.setY(loc.getY());
        mob.setHomeY(loc.getY());
        mob.setMap(loc.getMapId());
        mob.set_storeDroped(false);
        mob.setUbSealCount(0);

        L1World.getInstance().storeObject(mob);
        L1World.getInstance().addVisibleObject(mob);

        final S_NPCPack npcPack = new S_NPCPack(mob);
        for (final L1PcInstance pc : L1World.getInstance().getRecognizePlayer(
                mob)) {
            pc.addKnownObject(mob);
            mob.addKnownObject(pc);
            pc.sendPackets(npcPack);
        }
        // 怪物ＡＩ开始
        mob.onNpcAI();
        mob.updateLight();
        // mob.startChat(L1NpcInstance.CHAT_TIMING_APPEARANCE); // 开始喊话
        return mob;
    }

    /**
     * 启动任务.
     */
    public void start() { // 初始化
        this._preliminary = new Preliminary();
        this._hqm = new HardinQuestMonitor();
        GeneralThreadPool.getInstance().execute(this._preliminary);
        this._hqm.begin();
    }

    /**
     * 指定的PC瞬移到指定位置.
     * 
     * @param pc
     *            - 对象
     * @param loc
     *            - 坐标位置
     * @param heading
     *            - 面向
     */
    public void tereportEntrance(final L1PcInstance pc, final L1Location loc,
            final int heading) {
        L1Teleport.teleport(pc, loc, heading, true);
    }
}

/****************************** 信息输出顺序未知 **********************************/

// 7588 去死！都去死！
// 7589 这是什么游戏...
// 7590 所有的都能让我痴迷！
// 7591 这甜味是什么？血...？
// 7592 谁能填饱我的另一半。
// 7593 都会诅咒的
// 7594 学生和傻瓜是一种意思吗？
// 7595 唔...像爸爸...有种伟大的...感觉？
//
//
//
//
// 7812 [凯尔尼斯]什么时候来！
// 7813 [奥琳！]出什么事情了！
// 7814 [凯尔尼斯]没出什么事情吧！
//
// 7825 没有[凯尔尼斯]不行吗！
//
// 7826 诸位！没时间了！加油
//
// 7827 大家辛苦了。
//
// 7828 这是...香甜的血之香味...
// 7829 [凯尔尼斯]！赶紧振作点！
// 7830 这...声音是..命运的...车轮...转动的..
// 7831 把[凯尔尼斯]弄晕！
// 7832 呵...没有责任的老头...后面不是要交给你吗...就这程度吗...
//
// 7833 [凯尔尼斯]竟然晕倒了！
// 7834 诸位！速战速决也是减少受害的一种方法！
//
// 7835 这是什么现象!
// 7836 这地方要蹋了吗！就要成功了！！！
//
// ripper
//
//
// 7840 只要活着下次还有机会！先逃脱吧
//
//
//
//
// 7661 [亚希]！恩...阴谋吗...
// 7662 亚希
//
// 7667 这么快就开始了？
// 7668 [凯尔尼斯]终于来了！
// 7669 [凯尔尼斯]，在干什么！住手！
// 7670 啊...身体...不听使唤...
// 7671 [凯尔尼斯！！！]
// 7672 要把[凯尔尼斯]隔离！
//
// 7673 炎魔
//
//
// 7678 这是什么！
// 7679 危险！赶紧躲起来！
// 7680 现在的[凯尔尼斯]无法控制了！都逃跑吧！
//
// 7682 都逃脱吧！再待下去丢掉性命的！
// 7683 这次是失败啊！都逃脱吧！要封印这地方！
// 7684 呀！魔法阵在消失！
// 7685 都逃脱吧！要封印这地方！
// 7686 [奥！琳！]在这关键时刻去哪了！
// 7687 都逃跑吧！要封印这地方！
// 7688 ’还没好吗...’[凯尔尼斯]再坚持一会！
// 7689 [哈丁]..那家伙太强了！
// 7690 看来早就开始了！
// 7691 没有[凯尔尼斯]是不可能了！都逃脱吧！
// 7692 [凯尔尼斯]还没好吗！[奥琳]发生什么事情了！
//
//
//
// 7696 看来[凯尔尼斯]还没好。
// 7697 哈哈...[哈丁]，下次再见！
// 7698 [巴风特]消失吧。
// 7699 [凯尔尼斯]终于来了，拉住那魔物的视线！
// 7700 为什么这么快开始了！
// 7701 谁叫我了？哈哈哈！
// 7702 这是什么地方！卖肉的地方？
// 7703 [凯尔尼斯]终于来了！
// 7704 不...不是！[凯尔尼斯]怎么了！[奥琳]发生什么事了吧?
// 7705 [巴风特]，回到你主人那吧。
// 7706 住嘴！！！哈哈哈！[哈丁]下次再见吧！哈哈哈！
//
// 7707 真吃惊啊，竟然把[凯尔尼斯]弄晕..
// 7708 快..快逃跑！！！快！
//
// 7710 计划有误！快逃跑吧！
// 7711 [凯尔尼斯]！封印这地方的期间帮我耗时间！
//
//
// 7666 这...这是！快点逃跑！这地方要封印了！
// 7693 憋住气，赶紧逃脱！肺被那热气融化之前，快！
// 7674 这是你们的作品吗？
// 7675 是啊，这也是那位的意思...
// 7676 可能会有很多疑问，但那位魔法师急着上厕所。呵呵呵。
